APIDBConnection.md

March 12, 2024 ยท View on GitHub


API DB CONNECTION DOCUMENTATION

@capacitor-community/sqlite

SQLite DB Connection Wrapper

Methods Index

API DB Connection Wrapper

SQLiteDBConnection Interface

getConnectionDBName()

getConnectionDBName() => string

Get SQLite DB Connection DB name

Returns: string

Since: 2.9.0 refactor


getConnectionReadOnly()

getConnectionReadOnly() => boolean

Get SQLite DB Connection read-only mode

Returns: boolean

Since: 4.1.0


open()

open() => Promise<void>

Open a SQLite DB Connection

Since: 2.9.0 refactor


close()

close() => Promise<void>

Close a SQLite DB Connection

Since: 2.9.0 refactor


beginTransaction()

beginTransaction() => Promise<capSQLiteChanges>

Begin Database Transaction

Returns: Promise<capSQLiteChanges>

Since: 5.0.7


commitTransaction()

commitTransaction() => Promise<capSQLiteChanges>

Commit Database Transaction

Returns: Promise<capSQLiteChanges>

Since: 5.0.7


rollbackTransaction()

rollbackTransaction() => Promise<capSQLiteChanges>

Rollback Database Transaction

Returns: Promise<capSQLiteChanges>

Since: 5.0.7


isTransactionActive()

isTransactionActive() => Promise<capSQLiteResult>

Is Database Transaction Active

Returns: Promise<capSQLiteResult>

Since: 5.0.7


getUrl()

getUrl() => Promise<capSQLiteUrl>

Get Database Url

Returns: Promise<capSQLiteUrl>

Since: 3.3.3-4


getVersion()

getVersion() => Promise<capVersionResult>

Get the a SQLite DB Version

Returns: Promise<capVersionResult>

Since: 3.2.0


loadExtension(...)

loadExtension(path: string) => Promise<void>

Load a SQlite extension

ParamTypeDescription
pathstring:SQlite extension path

Since: 5.0.6


enableLoadExtension(...)

enableLoadExtension(toggle: boolean) => Promise<void>

Enable Or Disable Extension Loading

ParamTypeDescription
togglebooleantrue:on false:off

Since: 5.0.6


execute(...)

execute(statements: string, transaction?: boolean | undefined, isSQL92?: boolean | undefined) => Promise<capSQLiteChanges>

Execute SQLite DB Connection Statements

ParamTypeDescription
statementsstring
transactionboolean(optional)
isSQL92boolean(optional)

Returns: Promise<capSQLiteChanges>

Since: 2.9.0 refactor


query(...)

query(statement: string, values?: any[] | undefined, isSQL92?: boolean | undefined) => Promise<DBSQLiteValues>

Execute SQLite DB Connection Query

ParamTypeDescription
statementstring
valuesany[](optional)
isSQL92boolean(optional)

Returns: Promise<DBSQLiteValues>

Since: 2.9.0 refactor


run(...)

run(statement: string, values?: any[] | undefined, transaction?: boolean | undefined, returnMode?: string | undefined, isSQL92?: boolean | undefined) => Promise<capSQLiteChanges>

Execute SQLite DB Connection Raw Statement

ParamTypeDescription
statementstring
valuesany[](optional)
transactionboolean(optional)
returnModestring(optional)
isSQL92boolean(optional)

Returns: Promise<capSQLiteChanges>

Since: 2.9.0 refactor


executeSet(...)

executeSet(set: capSQLiteSet[], transaction?: boolean | undefined, returnMode?: string | undefined, isSQL92?: boolean | undefined) => Promise<capSQLiteChanges>

Execute SQLite DB Connection Set

ParamTypeDescription
setcapSQLiteSet[]
transactionboolean(optional)
returnModestring(optional)
isSQL92boolean(optional)

Returns: Promise<capSQLiteChanges>

Since: 2.9.0 refactor


isExists()

isExists() => Promise<capSQLiteResult>

Check if a SQLite DB Connection exists

Returns: Promise<capSQLiteResult>

Since: 2.9.0 refactor


isDBOpen()

isDBOpen() => Promise<capSQLiteResult>

Check if a SQLite database is opened

Returns: Promise<capSQLiteResult>

Since: 3.0.0-beta.5


isTable(...)

isTable(table: string) => Promise<capSQLiteResult>

Check if a table exists

ParamType
tablestring

Returns: Promise<capSQLiteResult>

Since: 3.0.0-beta.5


getTableList()

getTableList() => Promise<DBSQLiteValues>

Get database's table list

Returns: Promise<DBSQLiteValues>

Since: 3.4.2-3


delete()

delete() => Promise<void>

Delete a SQLite DB Connection

Since: 2.9.0 refactor


createSyncTable()

createSyncTable() => Promise<capSQLiteChanges>

Create a synchronization table

Returns: Promise<capSQLiteChanges>

Since: 2.9.0 refactor


setSyncDate(...)

setSyncDate(syncdate: string) => Promise<void>

Set the synchronization date

ParamType
syncdatestring

Since: 2.9.0 refactor


getSyncDate()

getSyncDate() => Promise<string>

Get the synchronization date

Returns: Promise<string>

Since: 2.9.0 refactor


exportToJson(...)

exportToJson(mode: string, encrypted?: boolean | undefined) => Promise<capSQLiteJson>

Export the given database to a JSON Object

ParamTypeDescription
modestring
encryptedboolean(optional) since 5.0.8 not for Web platform

Returns: Promise<capSQLiteJson>

Since: 2.9.0 refactor


deleteExportedRows()

deleteExportedRows() => Promise<void>

Remove rows with sql_deleted = 1 after an export

Since: 3.4.3-2


executeTransaction(...)

executeTransaction(txn: capTask[], isSQL92: boolean) => Promise<capSQLiteChanges>
ParamType
txncapTask[]
isSQL92boolean

Returns: Promise<capSQLiteChanges>

Since: 3.4.0


Interfaces

capSQLiteChanges

PropTypeDescription
changesChangesa returned Changes

Changes

PropTypeDescription
changesnumberthe number of changes from an execute or run command
lastIdnumberthe lastId created from a run command
valuesany[]values when RETURNING

capSQLiteResult

PropTypeDescription
resultbooleanresult set to true when successful else false

capSQLiteUrl

PropTypeDescription
urlstringa returned url

capVersionResult

PropTypeDescription
versionnumberNumber returned

DBSQLiteValues

PropTypeDescription
valuesany[]the data values list as an Array

capSQLiteSet

PropTypeDescription
statementstringA statement
valuesany[]the data values list as an Array

capSQLiteJson

PropTypeDescription
exportJsonSQLitean export JSON object

JsonSQLite

PropTypeDescription
databasestringThe database name
versionnumberThe database version
overwritebooleanDelete the database prior to import (default false)
encryptedbooleanSet to true (database encryption) / false
modestring* Set the mode ["full", "partial"]
tablesJsonTable[]* Array of Table (JsonTable)
viewsJsonView[]* Array of View (JsonView)

JsonTable

PropTypeDescription
namestringThe database name
schemaJsonColumn[]* Array of Schema (JsonColumn)
indexesJsonIndex[]* Array of Index (JsonIndex)
triggersJsonTrigger[]* Array of Trigger (JsonTrigger)
valuesany[][]* Array of Table data

JsonColumn

PropTypeDescription
columnstringThe column name
valuestringThe column data (type, unique, ...)
foreignkeystringThe column foreign key constraints
constraintstringthe column constraint

JsonIndex

PropTypeDescription
namestringThe index name
valuestringThe value of the index can have the following formats: email email ASC email, MobileNumber email ASC, MobileNumber DESC
modestringthe mode (Optional) UNIQUE

JsonTrigger

PropTypeDescription
namestringThe trigger name
timeeventstringThe trigger time event fired
conditionstringThe trigger condition
logicstringThe logic of the trigger

JsonView

PropTypeDescription
namestringThe view name
valuestringThe view create statement

capTask

PropTypeDescription
statementstringA SQLite statement
valuesany[]A set of values to bind to the statement (optional)