Introduction
Before some days I started a new project with blazor. I am using a MySQL database and I tried to work somehow with json documents in MySQL. During searching, I met this gratefull page : https://www.sitepoint.com/use-json-data-fields-mysql-databases/ . Then, I decided to create a nuget package that should do the full communication between my application and the json oriented database. Ready to know more? Let’s go!
Installation
In order to use the package, you just need to install it from here. Or directly with command:
Install-Package Xamabrouk.MySQLJsonBased
This package is using two other important packages :
- Xamabrouk.MySQLJsonBased.Entity : Provides entities used in the package. (Installation)
- Xamabrouk.MySQLJsonBased.Interface : Provides interfaces used in the package. (Installation)
Let’s code !
First of all, we create a new console .Net core project. The we install our package.
Then let’s say you want to manage user roles. Create than a UserRole
class. This class has to implement the interface IJsonTable
which defines the Id of your future DB-table, like:
public class UserRole : IJsonTable { public ObjectId Id { get; set; } public string Name { get; set; } public override string ToString() => $"{Id} : {Name}"; }
In the program class, you create a new instance of MySQLDriver
:
MySQLDriver driver = new MySQLDriver($"Server=YOUR_SERVER;Port=YOUR_PORT;Database=YOUR_DB;User=YOUR_USER;Pwd=USER_PASSWORD;");
Now, it is too easy to insert a new row in your table. You just need to call the method Save
or SaveAsync
:
bool result = driver.Save(new UserRole() { Name = "Administrator" });
Or,
bool result = await driver.SaveAsync<UserRole>(new UserRole());
The Save
method, calls the method Update
if the item exists already in the table, and Insert
if not.
The same game with Delete
and Async methods (SaveAsync
, UpdateAsync
, DeleteAsync
, etc. ) …
Note
You dont have to create the table manually in the database. When you callSave
the table will be created automatically if it doesn’t exists.
Table Structure

And here is an example of using the JsonTableAttribute
:
[JsonTable(name:"YourTableName",jsonFieldName:"JsonDocument")] public class UserRole : IJsonTable { public ObjectId Id { get; set; } public string Name { get; set; } public override string ToString() => $"{Id} => {Name}"; }
Now if you run the driver.Save(new UserRole() { Name = "Administrator" });
again, a new table ‘YourTableName’ will be created and a new row (new role in this case) will be inserted:

Conclusion
It’s very simple to use and learn this package. It has only one class MySQLDriver
that you can use also as a base class for other classes.
I hope you will enjoy this!
- Simple project : https://github.com/MabroukENG/MySQLJsonBasedSimple
- Source code: https://github.com/MabroukENG/MySQLJsonBased
Very cool!
Like!! I blog quite often and I genuinely thank you for your information. The article has truly peaked my interest.
Thanks so much for the blog post.
Thanks for fantastic info I was looking for this info for my mission.
Your site is very helpful. Many thanks for sharing!
Hello . i see that you have good daily visits on your blog , try to join our trusted ad network and make more extra money and get weekly payment >>> https://cutt.ly/adnetwork
we offer you replica diamond rolex for sale & favorite replica diamond rolex.
Hello .Do you eat at McDonalds ? if you from canada and eat at McDonalds , you can get free McDonalds Gift Card , this just for limited time , try now and get free meals >> http://lnkclik.com/95s7
Wow! At last I got a web site from where I be
able to genuinely take valuable information concerning my study and knowledge.
I will right away grasp your rss as I can’t
to find your email subscription hyperlink or newsletter service.
Do you’ve any? Please permit me realize in order that I may just subscribe.
Thanks.
Hello there! Do you know if they make any plugins to safeguard
against hackers? I’m kinda paranoid about losing
everything I’ve worked hard on. Any recommendations?
I all the time used to study piece of writing in news papers but now as I am a
user of internet therefore from now I am using net for articles or reviews,
thanks to web.
I quite like reading a post that can make people think.
Also, thanks for allowing me to comment!
When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is
added I get four e-mails with the same comment.
Is there any way you can remove people from that service?
Thanks a lot!
https://oncofertility.northwestern.edu/sites/oncofertility/files/webform/48zoMuK-FrEe-RObUX-gEnERatOR-RObUX-fRee-COdES-GEnErator-kAm150.pdf
I’ve been browsing online more than 3 hours today,
yet I never found any interesting article like
yours. It’s pretty worth enough for me. In my view, if all webmasters and bloggers made good content as you did, the web will be a lot more useful than ever before.
Hey There. I discovered your blog using msn. That is a really
neatly written article. I will make sure to bookmark
it and return to read more of your useful info.
Thank you for the post. I will definitely comeback.
constantly i used to read smaller content which as well clear
their motive, and that is also happening with this piece of writing which I am
reading now.
It’s really a nice and useful piece of information. I am satisfied that you
shared this useful information with us. Please stay us informed like this.
Thanks for sharing.
This piece of writing will assist the internet users for building up new website or even a weblog from start
to end.
Howdy, i read your blog from time to time and i own a similar one and i was just wondering if you get a lot of spam
comments? If so how do you prevent it, any plugin or anything you can advise?
I get so much lately it’s driving me crazy so any help is very much appreciated.
Good day! I could have sworn I’ve been to this site before but after reading through some of
the post I realized it’s new to me. Nonetheless,
I’m definitely happy I found it and I’ll
be bookmarking and checking back often!
We’re a group of volunteers and opening a
new scheme in our community. Your website offered
us with valuable info to work on. You have done an impressive job and our whole
community will be grateful to you.
Hi! I know this is kinda off topic but I was wondering which blog platform are you using for this website?
I’m getting tired of WordPress because I’ve had issues with hackers and I’m looking at options for another
platform. I would be awesome if you could point me in the direction of a good platform.
It’s very trouble-free to find out any topic on web as compared to books, as I found this piece of
writing at this site.
I don’t even know how I ended up here, but I thought this post was good.
I do not know who you are but certainly you’re
going to a famous blogger if you are not already 😉 Cheers!
Excellent beat ! I wish to apprentice even as you amend your site, how could i subscribe for a weblog website?
The account helped me a acceptable deal. I were tiny bit acquainted of this your broadcast provided vivid transparent idea
Wow! In the end I got a weblog from where I be capable of in fact obtain helpful
facts regarding my study and knowledge.
Hello all, here every one is sharing these kinds of familiarity, thus it’s good to read this web site, and I used to go to see this blog all the
time.
Hey there superb blog! Does running a blog similar to this take a great deal of
work? I have virtually no expertise in computer programming however I had been hoping to start my own blog soon. Anyway,
if you have any recommendations or techniques for new blog owners
please share. I understand this is off subject but I just needed to ask.
Thanks a lot!
Hey very nice blog!
Hello, after reading this remarkable article i am too happy to share my familiarity here with friends.
This is a pure gentlemanly post. Thankyou exchange for posting this amazing article.
xbody dristor
Hi, of course this article is genuinely good and I have learned lot of things from it on the topic of blogging.
thanks.
Hello would you mind letting me know which hosting company you’re
utilizing? I’ve loaded your blog in 3 completely
different internet browsers and I must say this blog loads a lot quicker then most.
Can you suggest a good hosting provider at a fair
price? Thank you, I appreciate it!
Definitely believe that which you stated. Your favorite reason appeared
to be on the net the simplest thing to be aware of. I say
to you, I certainly get annoyed while people think about worries that they plainly do not know
about. You managed to hit the nail upon the top and
defined out the whole thing without having side effect , people can take a signal.
Will likely be back to get more. Thanks
Its like you read my mind! You seem to know so much about this, like
you wrote the book in it or something. I think that you
could do with some pics to drive the message home a little bit, but other than that, this is
magnificent blog. A great read. I’ll certainly be back.
Fabulous, what a webpage it is! This weblog gives
valuable information to us, keep it up.
It’s an amazing post for all the internet people; they will obtain advantage from it I am sure.
Tremendous things here. I’m very happy to see your article.
Thanks a lot and I am taking a look forward to touch you.
Will you please drop me a mail?
Do you mind if I quote a few of your posts as long as I provide credit and sources
back to your weblog? My blog is in the exact same area of interest as yours and my users would certainly benefit from a lot
of the information you provide here. Please let me know if
this ok with you. Thank you!
Hey would you mind sharing which blog platform you’re
working with? I’m planning to start my own blog soon but I’m having a difficult time
deciding between BlogEngine/Wordpress/B2evolution and
Drupal. The reason I ask is because your design and style seems
different then most blogs and I’m looking for something unique.
P.S Sorry for getting off-topic but I had to ask!
For hottest news you have to visit the web and on the
web I found this web site as a finest web site for newest updates.
Heya i’m for the first time here. I came across this
board and I to find It truly helpful & it helped me out
much. I am hoping to provide something back and aid others
such as you helped me.
Wow, this article is fastidious, my sister is analyzing such things, so I am going to let
know her.
Thanks to my father who informed me regarding this weblog, this website is really amazing.
Inspiring quest there. What occurred after? Good luck!
I could not resist commenting. Very well written!