Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/khelechy/csjsondb
A C# package that performs basic CRUD ( Create, Read, Update, Delete ) operations on a Json file, used for sample minimalistic DBs.
https://github.com/khelechy/csjsondb
crud csharp csharp-library database db dotnet dotnet-core nuget
Last synced: 29 days ago
JSON representation
A C# package that performs basic CRUD ( Create, Read, Update, Delete ) operations on a Json file, used for sample minimalistic DBs.
- Host: GitHub
- URL: https://github.com/khelechy/csjsondb
- Owner: Khelechy
- License: mit
- Created: 2021-06-07T12:28:31.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-06-21T10:13:26.000Z (over 3 years ago)
- Last Synced: 2024-10-15T16:04:19.522Z (29 days ago)
- Topics: crud, csharp, csharp-library, database, db, dotnet, dotnet-core, nuget
- Language: C#
- Homepage:
- Size: 116 KB
- Stars: 81
- Watchers: 5
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CSJsonDB
## IntroductionThis is a simple C# package that performs basic CRUD ( Create, Read, Update, Delete ) operations on a Json file, used for sample minimalistic DBs.
## Installation
Install via .NET CLI
```bash
dotnet add package CSJsonDB --version 1.1.0
```
Install via Package Manager```bash
Install-Package CSJsonDB --version 1.1.0
```### Add the namespace directive `using CSJsonDB;` `IMPORTANT`
Sample DB `users.db`
```json
{
"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
}
]
}
```### Load the Sample DB `IMPORTANT`
```c#
var db = JsonDB.Load("filepathtosampledb/users.db");
```## Available Methods ๐งจ
>**NOTE**
>Responses are returned as objects. You can use `.ToJsonString()` method to return json string from a json object### Load
```c#
var db = JsonDB.Load(string filePath);
```### ToJsonString
```c#
db.Select("users").Where("id", 2).ToJsonString();
```
result: `string` Returns the json string of the object.### Select
```c#
db.Select(string table);
```#### Sample
```c#
db.Select("users");
```
result: `object`
```json
[
{
"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
}
]
```### Where
```c#
db.Select(string table).Where(string key, dynamic value);
```
#### Sample
```c#
db.Select("users").Where("id", 2);
```
result: `List`
```json
[
{
"id": 2,
"firstname": "john",
"lastname": "doe",
"age": 33,
"verified": true
},
]
```### Add
```c#
db.Add(string table, object newData);
```
#### Sample
```c#
var newUser = new {
id = 3,
firstname = matt,
lastname = doe,
age = 23,
verified = false
};db.Add("users", newUser);
```
result: void### Delete
```c#
db.Delete(string table, string key, dynamic value);
```
#### Sample
```c#
db.Delete("users", "id", 1);
```
result: void### Update
```c#
db.Update(string table, string key, dynamic value, object newData);
```
#### Sample
```c#
var updateUser = new {
verified = true
};db.Update("users", "id", 3, updateUser);
```
result: `object`
```json
[
{
"id": 3,
"firstname": "mark",
"lastname": "parker",
"age": 20,
"verified": true
},
]
```## Contribution
If you find an issue with this package or you have any suggestion please help out. I am not perfect.