SQLite

Improve this doc

$ ionic plugin add cordova-sqlite-storage
$ npm install --save @ionic-native/sqlite

Repo: https://github.com/litehelpers/Cordova-sqlite-storage

Access SQLite databases on the device.

Usage

import { SQLite, SQLiteObject } from '@ionic-native/sqlite';

constructor(private sqlite: SQLite) { }

...

this.sqlite.create({
  name: 'data.db',
  location: 'default'
})
  .then((db: SQLiteObject) => {


    db.executeSql('create table danceMoves(name VARCHAR(32))', {})
      .then(() => console.log('Executed SQL'))
      .catch(e => console.log(e));


  })
  .catch(e => console.log(e));

Instance Members

create(config)

Open or create a SQLite database file.

See the plugin docs for an explanation of all options: https://github.com/litehelpers/Cordova-sqlite-storage#opening-a-database

Param Type Details
config SQLiteDatabaseConfig

database configuration

Returns: Promise

echoTest()

Verify that both the Javascript and native part of this plugin are installed in your application

Returns: Promise<any>

deleteDatabase(config)

Deletes a database

Param Type Details
config SQLiteDatabaseConfig

database configuration

Returns: Promise<any>

SQLiteObject

Instance Members

databaseFeatures()

addTransaction()

transaction(fn)

Param Type Details
fn any

Returns: Promise<any>

readTransaction(fn)

Param Type Details
fn any

Returns: Promise<any>

startNextTransaction()

close()

Returns: Promise<any>

start()

executeSql()

Execute SQL on the opened database. Note, you must call create first, and ensure it resolved and successfully opened the database.

addStatement(sql, values)

Param Type Details
sql
values

Returns: Promise<any>

sqlBatch(sqlStatements)

Param Type Details
sqlStatements any

Returns: Promise<any>

abortallPendingTransactions()

handleStatementSuccess(handler, response)

Param Type Details
handler
response

handleStatementFailure(handler, response)

Param Type Details
handler
response

run()

abort(txFailure)

Param Type Details
txFailure

finish()

abortFromQ(sqlerror)

Param Type Details
sqlerror

SQLiteDatabaseConfig

Param Type Details
name string

Name of the database. Example: 'my.db'

location string

Location of the database. Example: 'default'

(optional)
iosDatabaseLocation string

iOS Database Location. Example: 'Library'

(optional)

API

Native

General