Home Demo Docs Git Repository

Getting started

To add it into your webpage you can use:

<script src="https://dandimrod.github.io/IndexSQL/src/IndexSQL.min.js" type="​​application/javascript"></script>

Javascript Docs

IndexSQL

Class that represents a single IndexSQL database

Parameters

execute

It executes several IndexSQL queries.

Parameters

drop

It drops the IndexSQL database. Afterwards the object is unusable and a new IndexSQL object has to be created.

backup

It backs up the database by returning the whole Javascript object that contanins the database.

Parameters

restore

It restores an old backup of the database. Warning! The system wont perform any checks on this backup. An incorrect restore will make the library fail.

Parameters

&& a.datatype === "NUMBER"

&& a.datatype === "NUMBER"

queryResult

The result of a IndexSQL query. It will contain at least one of these properties.

Type: Object

Properties

dbQueryCallback

Callback for queries execution.

Type: Function

Parameters

tableResultHeader

The headers of a result table

Type: Object

Properties

tableResult

The result table of a query.

Type: Object

Properties

dbBackupCallback

Callback for backup execution.

Type: Function

Parameters

IndexSQL language

(The symbols < and > means the parameter is optional)

CREATE TABLE

Syntax: “CREATE TABLE table_name (
column1 datatype <constraints>,
column2 datatype <constraints>,
....
PRIMARY KEY (columnName),
< FOREIGN KEY (columnName) REFERENCES foreignTableName(foreignTableColumn)>
);”

It creates the table table_name . It will contain the columns, with the datatypes and constraints specified, the constraints are optional, and they are:

The possible datatypes are:

IndexSQL will accept other SQL datatypes like VARCHAR but it will assign them one of the primitive datatypes and it won’t check the length of the columns data.

The primary key is a column that will act as the key to the whole column. It will be NOT_NULL and UNIQUE by default.

The foreign keys will be a series of keys that are related to another column in another table. It means that during the insertion, it will check if the value of the column exists on the foreign table.

DROP TABLE

Syntax: “DROP TABLE table_name;”

It will delete the table_name table and all their values. This action cannot be reverted.

TRUNCATE TABLE

Syntax: “DROP TRUNCATE table_name;”

It will delete all the values of the table_name table and leave it clean. This action cannot be reverted.

TABLES

Syntax: “TABLES;”

It will return a list with all the tables of the system.


INSERT INTO

Syntax:” INSERT INTO table_name <(column1, column2, column3, ...)>
VALUES (value1, value2, value3, ...);”

It will insert the values into the table_name. The columns are optional, if they are not specified, it will take the values in the order the table was originally created.

If the columns contain the primary key, and the primary key matches any other primary key of the table. It will rewrite the contents.

SELECT

Syntax:”SELECT <DISTINCT> column1, column2, ... FROM table_name <WHERE condition> <ORDER BY column1 ASC|DESC, column2 ASC|DESC, ... ;>”

It will return the values selected. To select all columns, you can write an asterisk (*) instead.

The DISTINCT parameter will make any rows that are the same to collapse into one.

The WHERE and ORDER BY statements are optional.

To see more about the WHERE statement, check this part of the documentation .

The ORDER BY will order the columns by the list provided, ASC means ascendant and DESC is descendant. If it’s not specified it will be ASC. If the columns are the same, it will check the next column in the list.

UPDATE

Syntax:” UPDATE table_name SET column1 = value1, column2 = value2, ... <WHERE condition;>”

It will update the columns with the new values provided.

The WHERE statement is optional, if it is not specified, it will update all the rows of the table.

To see more about the WHERE statement, check this part of the documentation .

DELETE

Syntax:” DELETE FROM table_name <WHERE condition>;

It will delete the columns.

The WHERE statement is optional, if it is not specified, it will delete all the rows of the table.

To see more about the WHERE statement, check this part of the documentation .

START TRANSACTION

Syntax: “START TRANSACTION;”

It starts a transaction, any operation performed during the transaction won’t be recorded into the database. Any errors encountered during a transaction will halt the execution of all the queries, including the ones outside the transaction.

END TRANSACTION

Syntax: ”END TRANSACTION:”

It ends a transaction, committing all the changes made during the transaction to the database.

The WHERE statement

Syntax: ”WHERE condition”

It will match the columns that check the conditions. It supports a series of operations:

Operator

Description

=

Equal

>

Greater than

<

Less than

>=

Greater than or equal

<=

Less than or equal

<>

Not equal.

AND

Logic and

OR

Logic or

NOT

Logic not

TRUE

Logic true

FALSE

Logic false

IS

Similar to =

NULL

Matches empty values

()

Used to separate between conditions



The following are some examples of WHERE statements:

SQL Coverage

From the standard SQL syntaxis, IndexSQL covers: