-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3c76b1
commit 4b1478c
Showing
1 changed file
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,22 +32,22 @@ If you want to use it, please check out the docs for the project. | |
|
||
### Project Goals | ||
|
||
- Store & Access key-value pairs | ||
- Store & Access key-value pairs (support for primitive & custom values) | ||
- Write stored data to disk | ||
- Load stored data from disk | ||
- Expose a dead simple API to developers | ||
- Don't include anything else other than Deno std | ||
|
||
<br></br> | ||
<br> | ||
|
||
<!-- USAGE --> | ||
## Usage | ||
|
||
This is the most basic example to get DsDDB up and running within your project. For further infroamtion check out the [API Documentation](https://doc.deno.land/https/deno.land/x/dsddb/mod.ts). | ||
|
||
```TypeScript | ||
// 1. Add import to your deps.ts | ||
export { DsDDB } from "https://deno.land/x/dsddb@v1.0.1/mod.ts"; | ||
// 1. Import DsDDB | ||
import { DsDDB } from "https://deno.land/x/dsddb@v1.1.0/mod.ts"; | ||
|
||
// 2. Create new DsDDB instance | ||
const database = new DsDDB(); | ||
|
@@ -56,10 +56,47 @@ const database = new DsDDB(); | |
await database.load(); | ||
|
||
// 4. Use database | ||
if (!database.exists("myKey")) database.set("myKey", "Hello World"); | ||
database.set("key1", "value 1") // Always override value. | ||
database.set("myKey", "Hello World", false); // Never override value. | ||
|
||
console.log(database.get("myKey")); | ||
|
||
// 5. Write data to disk | ||
await database.write(); | ||
``` | ||
|
||
|
||
If you want to store custom data structures, there's a solution to that as well. | ||
|
||
```TypeScript | ||
// 1. Import DsDDB | ||
import { DsDDB } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
// 2. Define your data structure. | ||
interface IDino { | ||
name: string; | ||
size: number; | ||
birthday: Date; | ||
} | ||
|
||
// 3. Define your data. | ||
let data1: IDino = { | ||
name: "Deno", | ||
size: 69, | ||
birthday: new Date() | ||
}; | ||
|
||
// 4. Create new DsDDB instance | ||
const database = new DsDDB<IDino>(); | ||
|
||
// 5. Load from disk | ||
await database.load(); | ||
|
||
// 6. Use database | ||
database.set("deno", data1) | ||
|
||
console.log(database.get("deno")); | ||
|
||
// 7. Write data to disk | ||
await database.write(); | ||
``` |