Check out Ionic Enterprise

SQLite

Improve this doc

Access SQLite databases on the device.

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

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-sqlite-storage
    $ npm install --save @ionic-native/sqlite
    
  2. Add this plugin to your app's module

Supported platforms

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()

openDBs()

addTransaction()

transaction(fn)

Param Type Details
fn any

Returns: Promise<any>

readTransaction(fn)

Param Type Details
fn Function

Returns: Promise<any>

startNextTransaction()

open()

Returns: Promise<any>

close()

Returns: Promise<any>

executeSql()

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

sqlBatch(sqlStatements)

Param Type Details
sqlStatements Array<string | string[]>

Returns: Promise<any>

abortallPendingTransactions()

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)
createFromLocation number

support opening pre-filled databases with https://github.com/litehelpers/cordova-sqlite-ext

(optional)

SQLiteTransaction

Param Type Details
start () => void
executeSql (sql: any, values: any, success: Function, error: Function) => void
addStatement (sql: any, values: any, success: Function, error: Function) => void
handleStatementSuccess (handler: Function, response: any) => void
handleStatementFailure (handler: Function, response: any) => void
run () => void
abort (txFailure: any) => void
finish () => void
abortFromQ (sqlerror: any) => void

API

Native

General