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

semsql

v1.1.0

Published

A semantic SQL syntax for JavaScript

Downloads

61

Readme

semsql

What is semSQL?

semSQL is a semantic-like SQLite library.

All your queries look like this:

db.CREATE.TABLE('foo')(['COL1', 'TEXT', 'NOT NULL']);

All Supported Queries

Note: If you are viewing this from the npm package listing, you should switch to our GitHub so the links work correctly. Otherwise, the below links will not work!

Generics

Database#runPreparedStatement(query, ...queryArgs) runs a prepared statement (usually used internally). This breaks the safety of using semsql.

Queries

CREATE

Used to create something.

Accessed by db.CREATE.

TABLE

Used to create a table.

Called by db.CREATE.TABLE(name: string). When called, a Function is returned, which is used to add columns.

db.CREATE.TABLE(name: string) => (...columns: [string, ...string[]][]) => void

Example:

db.CREATE.TABLE('Users')(
    ['id', 'INT', 'PRIMARY KEY'],
    ['firstName', 'TEXT', 'NOT NULL'],
    ['lastName', 'TEXT'],
    ['username', 'TEXT', 'UNIQUE', 'NOT NULL'],
    ['age', 'INT'],
    ['bio', 'TEXT']
);

INSERT

Used to add data to the database.

Accessed by db.INSERT.

INTO

Used to insert data into a table.

Called by db.INSERT.INTO(name: string). When called, an Object with one property (VALUES) is returned, which is used to add data.

db.INSERT.INTO(name: string) => { VALUES: (params: any[]) => void }

Example:

db.INSERT.INTO('Users').VALUES(1, 'John', 'Doe', 'JohnDoe', 50, "i'm john and i do things");

OR REPLACE INTO

Used to insert data into a table, or replace it if it already exists.

Called by db.INSERT.OR_REPLACE.INTO(name: string). When called, an Object with one property (VALUES) is returned, which is used to add data.

db.INSERT.OR_REPLACE.INTO(name: string) => { VALUES: (params: any[]) => void }

Example:

db.INSERT.OR_REPLACE.INTO('Users').VALUES(1, 'John', 'Doe', 'JohnDoe', 50, "i'm john and i do things");

SELECT ... FROM

Used to get data.

Called by db.SELECT(...columns: string[]). When called, an Object with one property (FROM) is returned, which is used to select the table.

columns can be "*" for all.

whereCall can be used as a WHERE statement. whereCall is an object with an array of arrays. The inner array is ['column', 'operator', 'value'], and each array is separated with AND. Ex.: whereCall: { WHERE: [['foo', '=', 'bar'], ['baz', '>', 'qux']] } is the same as WHERE foo = "bar" AND baz = "qux".

db.SELECT(...columns: string[]) => { FROM: (name: string, whereCall?: { WHERE: [string, '=' | '!=' | '>' | '>=' | '<' | '<=', any][] } }

Example:

db.SELECT('*').FROM('Users'); // => [ { id: 1, firstName: 'John', lastName: 'doe', username: 'JohnDoe', age: 50, bio: "i'm john and i do things" } ]
db.SELECT('id').FROM('Users'); // => [ { id: 1 } ]
db.SELECT('id').FROM('Users', { WHERE: [['id', '<=', 1]] }); // => [ { id: 1 } ]

DROP

Used to delete a table, etc.

Accessed by db.DROP.

TABLE

Warning: This function can cause data loss! (Deletes tables) Use at your own risk!

Delete a table and all of it's data.

Called by db.DROP.TABLE(name: string).

Example:

db.DROP.TABLE('Users'); // delete table 'Users'

BEGIN

Called by db.BEGIN().

All forms:

  • db.BEGIN()
  • db.BEGIN.TRANS()
  • db.BEGIN.TRANSACTION()

Creates a "transaction" to be rolled back with ROLLBACK or committed with COMMIT

ROLLBACK

Called by db.ROLLBACK().

All forms:

  • db.ROLLBACK()
  • db.ROLLBACK.TRANS()
  • db.ROLLBACK.TRANSACTION()

Rolls back a transaction.

COMMIT

Called by db.COMMIT().

All forms:

  • db.COMMIT()
  • db.COMMIT.TRANS()
  • db.COMMIT.TRANSACTION()

Commits a transaction.