Experimental port of begin/data from Node to Deno
- Deno >= 1.0.3
- Node >= 12.x and
npm i -g @architect/architect
- Run the linter
./begin lint
- Run the tests
./begin test
- Add further tasks in
app.arc
under the@begin
pragma
begin/data organizes collections of json documents by table
and key
. All
documents have these properties.
-
set(params:{table:string, key:string}):Promise<{table:string, key:string}>
-
set(params:{table:string}):Promise<{table:string, key:string}>
-
set(params:object[]):Promise<{table:string, key:string}[]>
Write any valid JSON document; please ensure required table
and key
properties exist.
import * as data from "https://deno.begin.com/data@latest/mod.ts";
await data.set({ table: "cats", key: "sutr0", cat: true });
-
get(params:{table:string, key:string, begin?:string}):Promise<{table:string, key:string}>
read one document -
get(params:{table:string}):Promise<{table:string, key:string}[]>
paginate documents -
get(params:object[]):Promise<{table:string, key:string}[]>
batch read documents
To read a single value pass named options table
and key
to get
.
import { get } from "https://deno.begin.com/data@latest/mod.ts";
let table = "people";
let key = "[email protected]";
let person = await get({ table, key });
// { table: "people", key: "[email protected]", role: "maintainer" }
To read the first ten records in a table just pass table
and no other
arguments:
let firstpage = await get({ table });
// [{table, key}, {table, key}, {table, key}, ...]
let cursor = firstpage.cursor;
// Xkasskieewxx9429kdad...
Paginate the table collection by passing cursor
back to get
:
let secondpage = await get({ table, cursor });
// [{table, key}, {table, key}, {table, key}, ...]
-
page(params:{table:string, limit:number, begin?:string}):AsyncIterator<{table:string, key:string}[]>
import { page } from "https://deno.begin.com/data@latest/mod.ts";
let pages = await page({ table: "accounts", limit: 5 });
for await (let account of pages) {
console.log(account);
}
-
destroy(params:{table:string, key:string}):Promise<void>
-
destroy(params:object[]):Promise<void>
-
incr(params:{table:string, key:string, prop:string):Promise<{table:string, key:string, prop:number}>
-
decr(params:{table:string, key:string, prop:string):Promise<{table:string, key:string, prop:number}>
-
count(params:{table:string}):Promise<number>