Giter Club home page Giter Club logo

deno-begin-data's Introduction

deno-begin-data

Experimental port of begin/data from Node to Deno

prereq

  • Deno >= 1.0.3
  • Node >= 12.x and npm i -g @architect/architect

contrib

  • Run the linter ./begin lint
  • Run the tests ./begin test
  • Add further tasks in app.arc under the @begin pragma

api

begin/data organizes collections of json documents by table and key. All documents have these properties.

writing documents with set

  • 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}[]>

set examples

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 });

reading documents with get

  • 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

get examples

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}, ...]

async iteration with page

  • page(params:{table:string, limit:number, begin?:string}):AsyncIterator<{table:string, key:string}[]>

page example

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 documents

  • destroy(params:{table:string, key:string}):Promise<void>
  • destroy(params:object[]):Promise<void>

atomic counters

  • 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>

deno-begin-data's People

Contributors

brianleroux avatar kristoferjoseph avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.