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!
-
CREATE
-
TABLE
(implemented in v0.1.0)
-
-
INSERT
-
INTO
(implemented in v0.1.0) -
OR REPLACE INTO
(implemented in v0.3.0-0)
-
-
SELECT ... FROM
(implemented in v0.1.0) -
DROP
-
TABLE
(implemented in v0.1.0)
-
-
BEGIN
(implemented in v0.2.0-0) -
ROLLBACK
(implemented in v0.2.0-0) -
COMMIT
(implemented in v0.2.0-0)
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.