npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

websql-json

v0.1.5

Published

Web SQLite access library. Communicate easily and cleanly using JSON objects.

Downloads

2

Readme

Web SQLite access library. Communicate easily and cleanly using JSON objects.

Usage

var local = require('websql-json');

Connect:

  • Use this method in order to connect to the database

If you call the connect method at the start, you do not need to include the name field on subsequent transactions.

local.connect(data, callback);

var data = {
    name: 'database_name',
    version: '1.0',
    descr: 'database_description',
    size: 500000,
};

// or

var data = {
    name: 'database_name',
};
  • The name field is mandatory and must be defined.
  • version, descr and size are all optional fields.
    • The default value for version is 1.0. It can only be 1.0 or 2.0.
    • The default value for descr will be the same as the name of the database.
    • The default value for size is 500000. Its maximum value is 52428000.

Create:

  • Use this method in order to create a table
local.transaction('create', data, callback);

// The `columns` field must be an array of strings

var data = {
    name: 'database_name',
    data: [
        {
            table: 'table_a',
            columns: ['col1', 'col2'],
        },
        {
            table: 'table_b',
            columns: ['col3', 'col4'],
        },
    ],
    inserts: [
        name: 'database_name',
        data: [
            {
                table: 'table_a',
                data: {
                    col1: 'val1',
                    col2: 'val2',
                },
            },
            {
                table: 'table_b',
                data: {
                    col3: 'val3',
                    col4: 'val4',
                },
            },
        ],
    ],
};

Drop:

  • Use this method in order to delete a table and all of its contents
local.transaction('drop', data, callback);

var data = {
    name: 'database_name',
    data: [
        {
            table: 'table_a',
        },
        {
            table: 'table_b',
        },
    ],
};

Insert:

  • Use this method to insert data into a table
    • Multi-row insertion is also possible
local.transaction('insert', data, callback);

var data = {
    name: 'database_name',
    data: [
        {
            table: 'table_a',
            data: {
                col1: 'val1',
                col2: 'val2',
            },
        },
        {
            table: 'table_b',
            data: {
                col3: 'val3',
                col4: 'val4',
            },
        },
    ],
};

// `data` must be an array of JSON objects. e.g.

var data = {
    name: 'database_name',
    data: [
        {
            table: 'devices',
            name: 'device 1',
            type: 'ctrl',
        },
        {
            table: 'devices',
            name: 'device 2',
            type: 'ctrl',
        },
    ],
};

Delete:

  • Use this method in order to delete data from a table
local.transaction('delete', data, callback);

// Delete data where `col1` has a value of `val1`

var data = {
    name: 'database_name',
    table: 'table_name',
    data: {
        col1: 'val1',
    },
};

// Or delete all data from the table

var data = {
    name: 'database_name',
    table: 'table_name',
    data: {},
};

Update:

  • Use this method to update data in a table
local.transaction('update', data, callback);

var data = {
    name: 'database_name',
    table: 'table_name',
    data: {
        set: {
            col1: 'val1',
            col2: 'val2',
        },
        where: {
            col3: 'val3',
            col4: 'val4',
        },
    },
};

// `set` and `where` must be JSON objects with one or many key value pairs. e.g.

var data = {
    name: 'database_name',
    table: 'devices',
    data: {
        set: {
            name: 'new_device',
        },
        where: {
            type: 'ctrl',
            mac: 'ff',
        },
    },
};
  • This generates the SQL: UPDATE devices SET name='new_device' WHERE type='ctrl' AND mac='ff';
    • In this case the set condition is applied to all rows of the table.
  • set cannot be empty
  • where can be empty

Find:

  • Use this method to search a database table for a particular piece of data
local.transaction('find', data, callback);

// Find data where `col1` has a value of `val1` or `val2` or `val3` and `col2` has a value of `val4`
// Additionally join on `table_b` and select all columns from `table_b`

var data = {
    name: 'database_name',
    table: 'table_a',
    data: {
        col1: ['val1', 'val2', 'val3'],
        col2: 'val4',
    },
    join: {
        query: 'JOIN table_b on table_a.join_id = table_b.id',
    },
    selects: 'table_b.*',
    orderBy: ['join_id'],
};

// Or find and return all data from `table_a`

var data = {
    name: 'database_name',
    table: 'table_a',
    data: {},
};

Result

  • The result of all the methods will be a JSON object
var callbackData = {
    // Returned from a CREATE transaction when additional INSERT data is provided
    // This allows an INSERT transaction to proceed directly after a CREATE
    callbackData: { data: [], name: 'database_name' },

    done: flag,
    message: message,
    queryType: queryType,

    // Returned from a FIND transaction as an `SQLResultSetRowList`
    rows: [],
};
  • done returns true if the database call is successful, or false if it is not
  • queryType returns the type of query that was executed (e.g. "create", "insert", etc.)
  • message returns a success or failure string (e.g. "Table created successfully")
  • In case of a FIND transaction the result is returned under a rows object key