This is a simple C# package that performs basic CRUD ( Create, Read, Update, Delete ) operations on a Json file, used for sample minimalistic DBs.
Install via .NET CLI
dotnet add package CSJsonDB --version 1.1.0
Install via Package Manager
Install-Package CSJsonDB --version 1.1.0
Sample DB users.db
{
"users": [
{
"id": 1,
"firstname": "kelechi",
"lastname": "onyekwere",
"age": 19,
"verified": true
},
{
"id": 2,
"firstname": "john",
"lastname": "doe",
"age": 33,
"verified": true
},
{
"id": 3,
"firstname": "mark",
"lastname": "parker",
"age": 20,
"verified": false
}
]
}
var db = JsonDB.Load("filepathtosampledb/users.db");
NOTE
Responses are returned as objects. You can use.ToJsonString()
method to return json string from a json object
var db = JsonDB.Load(string filePath);
db.Select("users").Where("id", 2).ToJsonString();
result: string
Returns the json string of the object.
db.Select(string table);
db.Select("users");
result: object
[
{
"id": 1,
"firstname": "kelechi",
"lastname": "onyekwere",
"age": 19,
"verified": true
},
{
"id": 2,
"firstname": "john",
"lastname": "doe",
"age": 33,
"verified": true
},
{
"id": 3,
"firstname": "mark",
"lastname": "parker",
"age": 20,
"verified": false
}
]
db.Select(string table).Where(string key, dynamic value);
db.Select("users").Where("id", 2);
result: List<dynamic>
[
{
"id": 2,
"firstname": "john",
"lastname": "doe",
"age": 33,
"verified": true
},
]
db.Add(string table, object newData);
var newUser = new {
id = 3,
firstname = matt,
lastname = doe,
age = 23,
verified = false
};
db.Add("users", newUser);
result: void
db.Delete(string table, string key, dynamic value);
db.Delete("users", "id", 1);
result: void
db.Update(string table, string key, dynamic value, object newData);
var updateUser = new {
verified = true
};
db.Update("users", "id", 3, updateUser);
result: object
[
{
"id": 3,
"firstname": "mark",
"lastname": "parker",
"age": 20,
"verified": true
},
]
If you find an issue with this package or you have any suggestion please help out. I am not perfect.