0.1.0-alpha • Published 4 years ago

@asdine/genji v0.1.0-alpha

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Experimental wrapper around the Genji database.

It's functional but, currently, the compiled WebAssembly file is too big (~3mb) to be objectively usable in production.

The code is compatible with TinyGo and produces a 400kb wasm file but there are too many bugs in the v0.12.0, I will wait for the next version to give a try.

Getting started

Install Genji

yarn add @asdine/genji

Copy the wasm file from node_modules into your public directory

cp node_modules/@asdine/genji/genji.wasm public/

Or if you are using Webpack, add this to your config, after installing the copy-webpack-plugin loader :

yarn add --dev copy-webpack-plugin
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
    ...
    plugins: [
        new CopyWebpackPlugin([
            { from: 'node_modules/@asdine/genji/dist/genji.wasm' }
        ])
    ]
}

Usage

import { initDatabase } from '@asdine/genji';

async function run() {
    const genji = await initDatabase();
    const db = await genji.Database();
    await db.exec("CREATE TABLE foo");
    await db.exec("INSERT INTO foo (a) VALUES (1), (2), (3)");

    db.query("SELECT * FROM foo").
        forEach((v) => console.log(v));
}

run()

Build from source

Requires Go >= 1.13 and Node >= 10

yarn install
yarn build

Running tests

yarn test