Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jsejcksn/deno-kv-sqlite
Key-Value storage backed by SQLite
https://github.com/jsejcksn/deno-kv-sqlite
database deno key-value kv-store sqlite sqlite3
Last synced: 3 months ago
JSON representation
Key-Value storage backed by SQLite
- Host: GitHub
- URL: https://github.com/jsejcksn/deno-kv-sqlite
- Owner: jsejcksn
- License: mit
- Created: 2022-08-26T21:37:45.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-05T18:50:41.000Z (4 months ago)
- Last Synced: 2024-10-12T00:35:14.153Z (4 months ago)
- Topics: database, deno, key-value, kv-store, sqlite, sqlite3
- Language: TypeScript
- Homepage: https://deno.land/x/kv_sqlite
- Size: 29.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kv_sqlite
Key-Value storage backed by [SQLite](https://sqlite.org/) (uses
[`deno.land/x/sqlite`](https://deno.land/x/sqlite))- JavaScript
[`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)-like
API- Stores keys and values as strings (like the
[Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API))## API documentation
Generated TypeScript API documentation is available at
[`https://deno.land/x/kv_sqlite/mod.ts`](https://deno.land/x/kv_sqlite/mod.ts)## Use
```ts
import { openKVDb } from "https://deno.land/x/kv_sqlite@VERSION/mod.ts";// Open a persistent database using the local file system (it will be created if necessary):
const kv = openKVDb("path/to/kv-database.sqlite3");// Or open a database in-memory (not persisted)
// const kv = openKVDb();kv.set("hello", "world");
console.log(kv.get("hello")); // "world"// Retrieving values for non-existing keys returns `null`
console.log(kv.get("not a key yet")); // null// Has convenience methods for working with JSON-serializable values:
kv.json.set("foo", { bar: "baz" });
console.log(kv.json.get("foo").bar); // "baz"console.log(kv.size); // 2
// Be careful with this method (it deletes everything from the database!)
kv.clear();
console.log(kv.size); // 0// Close the database when finished to avoid leaking resources:
kv.close();
```