android-database-sqlite
v8.0.2
Published
Simple Capacitor wrapper around android.database.sqlite
Maintainers
Readme
android-database-sqlite
Simple Capacitor wrapper around android.database.sqlite
Maintainers
| Maintainer | GitHub | | ---------- | ------------------------------------------------------------------- | | Sergio | sergio-ponce-dominguez |
Supported Platform
- Android
Install
npm install android-database-sqlite
npx cap syncAPI
echo(...)openOrCreateDatabase(...)isOpen(...)close(...)execSQL(...)rawQuery(...)insert(...)getLastInsertRowId(...)getLastChangedRowCount(...)update(...)delete(...)beginTransaction(...)setTransactionSuccessful(...)endTransaction(...)getVersion(...)setVersion(...)- Type Aliases
echo(...)
echo(options: { value: string; }) => Promise<{ value: string; }>Return the same value passed in. Useful for basic connectivity / wiring tests.
| Param | Type |
| ------------- | ------------------------------- |
| options | { value: string; } |
Returns: Promise<{ value: string; }>
openOrCreateDatabase(...)
openOrCreateDatabase(options: { name?: string; }) => Promise<{ name: string; }>Open an existing database by name or create it if it does not exist. Behavior mirrors Android's SQLiteDatabase.openOrCreateDatabase: it ensures a database with the given name is available for use.
| Param | Type |
| ------------- | ------------------------------- |
| options | { name?: string; } |
Returns: Promise<{ name: string; }>
isOpen(...)
isOpen(options: { name?: string; }) => Promise<{ value: boolean; }>Check whether the named database is currently open.
| Param | Type |
| ------------- | ------------------------------- |
| options | { name?: string; } |
Returns: Promise<{ value: boolean; }>
close(...)
close(options: { name?: string; }) => Promise<void>Close the named database. After calling this, the database should no longer be used until reopened.
| Param | Type |
| ------------- | ------------------------------- |
| options | { name?: string; } |
execSQL(...)
execSQL(options: { name?: string; sql: string; bindArgs?: any[]; getChanges?: boolean; }) => Promise<{ changes?: number; lastId?: number; }>Execute a single SQL statement that does not return results (for example DDL or INSERT/UPDATE/DELETE without returning rows).
| Param | Type |
| ------------- | ------------------------------------------------------------------------------------ |
| options | { name?: string; sql: string; bindArgs?: any[]; getChanges?: boolean; } |
Returns: Promise<{ changes?: number; lastId?: number; }>
rawQuery(...)
rawQuery(options: { name?: string; sql: string; selectionArgs?: any[]; }) => Promise<{ rows: any[]; }>Run a SELECT query and return the resulting rows.
This mirrors SQLiteDatabase.rawQuery: the SQL may contain '?' placeholders that will be replaced by selectionArgs in order.
| Param | Type |
| ------------- | ------------------------------------------------------------------- |
| options | { name?: string; sql: string; selectionArgs?: any[]; } |
Returns: Promise<{ rows: any[]; }>
insert(...)
insert(options: { name?: string; table: string; values: Record<string, any>; }) => Promise<{ id: number; }>Insert a row into a table.
Mirrors SQLiteDatabase.insert: values is a map of column names to values.
| Param | Type |
| ------------- | ------------------------------------------------------------------------------------------------------- |
| options | { name?: string; table: string; values: Record<string, any>; } |
Returns: Promise<{ id: number; }>
getLastInsertRowId(...)
getLastInsertRowId(options: { name?: string; }) => Promise<{ lastId: number; }>Return the "rowId" of the last row to be inserted on the current connection.
Mirrors SQLiteDatabase.getLastInsertRowId.
| Param | Type |
| ------------- | ------------------------------- |
| options | { name?: string; } |
Returns: Promise<{ lastId: number; }>
getLastChangedRowCount(...)
getLastChangedRowCount(options: { name?: string; }) => Promise<{ changes: number; }>Return the number of database rows that were inserted, updated, or deleted by the most recent SQL statement within the current transaction.
Mirrors SQLiteDatabase.getLastChangedRowCount.
| Param | Type |
| ------------- | ------------------------------- |
| options | { name?: string; } |
Returns: Promise<{ changes: number; }>
update(...)
update(options: { name?: string; table: string; values: Record<string, any>; whereClause?: string; whereArgs?: any[]; }) => Promise<{ rowsAffected: number; }>Update rows in a table.
Mirrors SQLiteDatabase.update: updates rows that match the whereClause (which may contain '?' placeholders replaced by whereArgs).
| Param | Type |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| options | { name?: string; table: string; values: Record<string, any>; whereClause?: string; whereArgs?: any[]; } |
Returns: Promise<{ rowsAffected: number; }>
delete(...)
delete(options: { name?: string; table: string; whereClause?: string; whereArgs?: any[]; }) => Promise<{ rowsAffected: number; }>Delete rows from a table.
Mirrors SQLiteDatabase.delete: deletes rows that match the whereClause (which may contain '?' placeholders replaced by whereArgs).
| Param | Type |
| ------------- | --------------------------------------------------------------------------------------- |
| options | { name?: string; table: string; whereClause?: string; whereArgs?: any[]; } |
Returns: Promise<{ rowsAffected: number; }>
beginTransaction(...)
beginTransaction(options: { name?: string; }) => Promise<void>Begin a transaction on the named database. Subsequent operations will be part of the transaction until endTransaction is called.
Note: transaction semantics (exclusive, deferred, etc.) follow the plugin's implementation and are intended to match Android's default behavior.
| Param | Type |
| ------------- | ------------------------------- |
| options | { name?: string; } |
setTransactionSuccessful(...)
setTransactionSuccessful(options: { name?: string; }) => Promise<void>Mark the current transaction as successful. When endTransaction is called, if setTransactionSuccessful was called, the transaction will be committed; otherwise it will be rolled back.
| Param | Type |
| ------------- | ------------------------------- |
| options | { name?: string; } |
endTransaction(...)
endTransaction(options: { name?: string; }) => Promise<void>End a transaction. Commits if setTransactionSuccessful was called on the current transaction, otherwise rolls back.
| Param | Type |
| ------------- | ------------------------------- |
| options | { name?: string; } |
getVersion(...)
getVersion(options: { name?: string; }) => Promise<{ version: number; }>Get the user_version PRAGMA for the database. This is commonly used to store the schema version.
| Param | Type |
| ------------- | ------------------------------- |
| options | { name?: string; } |
Returns: Promise<{ version: number; }>
setVersion(...)
setVersion(options: { name?: string; version: number; }) => Promise<void>Set the user_version PRAGMA for the database. Used to record schema version.
| Param | Type |
| ------------- | ------------------------------------------------ |
| options | { name?: string; version: number; } |
Type Aliases
Record
Construct a type with a set of properties K of type T
{ [P in K]: T; }
