Since

1.0

See

Database is query friendly persisted data interface for perfoming database operations using SQLite. You can open database from assets or create/open database from file system. Also you can create in-memory database too. We recommend to use Squel.js library for creating SQL Queries.

Example

import File from '@smartface/native/io/file';
import Database from '@smartface/native/data'.Database;

var database = new Database({
file: new File({path: 'assets://database.sqlite'})
});

// Creating person table
database.execute("CREATE TABLE 'person' ( 'id' INTEGER, 'name' TEXT DEFAULT 'Smartface', 'age' INTEGER DEFAULT 5, 'isWorker' INTEGER DEFAULT 0, 'rate' REAL DEFAULT 2.5, PRIMARY KEY('id') )");

// Inserting values into person
database.execute("INSERT INTO person (name, age, isWorker, rate) VALUES ('George', 47, 0, 1.2)");
database.execute("INSERT INTO person (name, age, isWorker, rate) VALUES ('James', 40, 1, 3.4)");
database.execute("INSERT INTO person (name, age, isWorker, rate) VALUES ('Alex', 25, 1, 1.7)");

// Getting workers count
var queryResult = database.query("SELECT * FROM person WHERE(isWorker = 1)");
console.log("Worker count is: " + queryResult.count());

Hierarchy

  • Database

Implements

Constructors

Properties

Methods

Constructors

  • Parameters

    • Optional params: { file?: FileImpl; inMemory?: boolean }
      • Optional file?: FileImpl
      • Optional inMemory?: boolean

    Returns Database

Properties

file: FileImpl

The file for creating/opening database from it. If the given file is Assets, the database will be open but if assets not exists the exception will thrown. The parameter will setted if only given in constructor.

Property

Android

Ios

Throws

Since

1.0

inMemory: Boolean

A boolean value that represents database object is in-memory or not. In-memory databases are a way faster than normal databases but in-memory databases are temporary, you can not save them into a file. When database closes or application stopped, database will be destroyed. The parameter will setted if only given in constructor.

Property

Android

Ios

Throws

See

Since

1.0

nativeObject: any

Methods

  • Close the database. You should close the database after you done your job. If you don't, you will not open the database until close and will throw exception if you want to reopen it.

    Method

    close

    Android

    Ios

    Throws

    Since

    1.0

    Returns void

  • Execute Non SELECT SQL Command on Database. Method will thrown exception when execution failed.

    Method

    execute

    Android

    Ios

    Throws

    See

    https://sqlite.org/lang.html

    Since

    1.0

    Parameters

    • query: string

    Returns void

  • Execute SELECT SQL Command on Database. Method will thrown exception when execution failed.

    Returns

    Method

    query

    Android

    Ios

    Throws

    See

    https://sqlite.org/lang.html

    Since

    1.0

    Parameters

    • query: string

    Returns undefined | QueryResult

Generated using TypeDoc