Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lino-levan/otama
The KV abstraction for Deno KV
https://github.com/lino-levan/otama
Last synced: about 2 months ago
JSON representation
The KV abstraction for Deno KV
- Host: GitHub
- URL: https://github.com/lino-levan/otama
- Owner: lino-levan
- Created: 2023-05-23T17:46:26.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-05-23T17:48:40.000Z (over 1 year ago)
- Last Synced: 2024-06-20T16:09:32.384Z (3 months ago)
- Language: TypeScript
- Homepage: https://deno.land/x/otama
- Size: 3.91 KB
- Stars: 12
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Otama
> Otama is short for Otamajakushi which means tadpole.
Otama is an abstraction built for Deno KV which still exposes a simple KV API
but with a lot of syntactic sugar to make development easier!## Usage
First we should initialize the Ota object. Ota forces a strong definition of
your KV schema which allows for type checking!```ts
// example.ts
import { open } from "https://deno.land/x/otama/mod.ts";const ota = await open(
{
tables: {
servers: {
name: "nullable string",
user_count: "number",
},
users: {
name: "string",
email: "string",
},
},
} as const,
);
```Ota has strong typings for tables, meaning you'll never accidentally put invalid
data into your KV store again!```ts
await ota.servers.set("demo", {
name: "Demo Server",
user_count: 0,
// description: "This is a demo server", // This would error during type checking!
});
```Ota makes atomic operations as simple as possible. Use the same operations you
are used to but now they're magically atomic!```ts
await ota.atomic(async () => {
await ota.users.set("new_user", {
name: "New User",
email: "[email protected]",
});const server = await ota.servers.get("demo");
await ota.servers.update("demo", {
user_count: server.user_count + 1,
});
});
```Run the example using the following command
```bash
$ deno run --unstable https://deno.land/x/otama/example.ts
```