Skip to content

Commit

Permalink
Merge pull request #1 from IuryPiva/master
Browse files Browse the repository at this point in the history
Update dependencies, remove `--unstable` flag, add deno fmt and replace deprecated methods
  • Loading branch information
MaximilianHeidenreich authored Dec 14, 2021
2 parents f3b4cf9 + 175d119 commit 75bd16c
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 280 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ jobs:

strategy:
matrix:
deno: [1.6.1, 1.5.1]
name: Test with Deno ${{ matrix.deno }}
deno: [1.16.4]
name: Test with Deno ${{ matrix.deno }}

steps:
- uses: actions/checkout@master
Expand All @@ -17,16 +17,11 @@ jobs:
with:
deno-version: ${{ matrix.deno }}

- name: Setup Node
uses: actions/setup-node@master
with:
node-version: 12

- name: Print deno version
run: deno --version

#- name: Check format
# run: deno fmt --check **/*.ts
- name: Check format
run: deno fmt --check

- name: Run tests
run: deno test --unstable --allow-read --allow-write
run: deno test --allow-read --allow-write
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.vscode/
.dsddb/
10 changes: 5 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"deno.enable": true,
"deno.import_intellisense_origins": {
"https://deno.land": true
},
}
"deno.enable": true,
"deno.suggest.imports.hosts": {
"https://deno.land": true
}
}
49 changes: 28 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

<!-- PROJECT LOGO -->
<br />
<p align="center">
<a href="https://github.com/MaximilianHeidenreich/DsDDB">
<img src="https://deno.land/images/deno_matrix.png" alt="Deno Logo" width="80" height="80">
</a>

<h2 align="center">DsDDB</h2>
<h2 align="center">DsDDB</h2>

<p align="center">
A lightweight, develoepr friendly, key-value persistant storage solution for Deno projects</a>.
<p align="center">
A lightweight, developer friendly, key-value persistant storage solution for Deno projects</a>.
<br />
<a href="https://doc.deno.land/https/deno.land/x/dsddb/mod.ts"><strong>Explore the docs »</strong></a>
<br />
Expand All @@ -21,12 +20,17 @@
</p>

<br><br>

<!-- ABOUT THE PROJECT -->

## About The Project

I created this project because I needed a super simple key-value database which could store data between script restarts. This is the result of that attempt.
I created this project because I needed a super simple key-value database which
could store data between script restarts. This is the result of that attempt.

Obviously it can't hold up with "real" databases but if you are just starting out developing a new project and you want a dead simple way to store data, this probably is the solution for you.
Obviously it can't hold up with "real" databases but if you are just starting
out developing a new project and you want a dead simple way to store data, this
probably is the solution for you.

If you want to use it, please check out the docs for the project.

Expand All @@ -41,15 +45,19 @@ If you want to use it, please check out the docs for the project.
<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).
This is the most basic example to get DsDDB up and running within your project.
For further information check out the
[API Documentation](https://doc.deno.land/https/deno.land/x/dsddb/mod.ts).

> ! Note: If you are using the load() and write() methods, you need to run your Deno program with the "--unstable --allow-read --allow-write" flags.
> ! Note: If you are using the load() and write() methods, you need to run your
> Deno program with the "--allow-read --allow-write" flags.
```TypeScript
// 1. Import DsDDB
import { DsDDB } from "https://deno.land/x/dsddb@v2.0.0/mod.ts";
import { DsDDB } from "https://deno.land/x/dsddb@v2.1.0/mod.ts";

// 2. Create new DsDDB instance
const database = new DsDDB();
Expand All @@ -58,34 +66,33 @@ const database = new DsDDB();
await database.load();

// 4. Use database
database.set("key1", "value 1") // Always override value.
database.set("myKey", "Hello World", false); // Never override value.
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/dsddb@v2.0.0/mod.ts";
import { DsDDB } from "https://deno.land/x/dsddb@v2.1.0/mod.ts";

// 2. Define your data structure.
interface IDino {
name: string;
size: number;
birthday: Date;
name: string;
size: number;
birthday: Date;
}

// 3. Define your data.
let data1: IDino = {
name: "Deno",
size: 69,
birthday: new Date()
name: "Deno",
size: 69,
birthday: new Date(),
};

// 4. Create new DsDDB instance
Expand All @@ -95,10 +102,10 @@ const database = new DsDDB<IDino>();
await database.load();

// 6. Use database
database.set("deno", data1)
database.set("deno", data1);

console.log(database.get("deno"));

// 7. Write data to disk
await database.write();
```
```
3 changes: 1 addition & 2 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { createHash } from "https://deno.land/[email protected]/hash/mod.ts";
export { exists } from "https://deno.land/[email protected]/fs/mod.ts";
export { Md5 } from "https://deno.land/[email protected]/hash/md5.ts";
36 changes: 36 additions & 0 deletions mod.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { DsDDB } from "./mod.ts";
import { assertExists, assertThrows } from "./test_deps.ts";

Deno.test("Empty DB", async () => {
let db = new DsDDB();
await db.load();
await db.write();

assertThrows(() => Deno.readFileSync(db.storePath));
});

Deno.test("Simple Numer DB", async () => {
let db = new DsDDB();
await db.load();

db.set("number1", 5);
db.set("number2", 10);

await db.write();

assertExists(Deno.readFileSync(db.storePath));
await Deno.remove(db.storePath);
});

Deno.test("DB delete store", async () => {
let db = new DsDDB();
await db.load();

db.set("number1", 5);
db.set("number2", 10);

await db.write();
assertExists(Deno.readFileSync(db.storePath));
await db.deleteStore();
assertThrows(() => Deno.readFileSync(db.storePath));
});
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./src/dsddb.ts";
export * from "./src/dsddb.ts";
52 changes: 0 additions & 52 deletions mod_test.ts

This file was deleted.

Loading

0 comments on commit 75bd16c

Please sign in to comment.