expo-sqlite
Advanced tools
Comparing version
import './polyfillNextTick'; | ||
import { WebSQLDatabase } from './SQLite.types'; | ||
/** | ||
* Open a database, creating it if it doesn't exist, and return a `Database` object. On disk, | ||
* the database will be created under the app's [documents directory](../filesystem), i.e. | ||
* `${FileSystem.documentDirectory}/SQLite/${name}`. | ||
* > The `version`, `description` and `size` arguments are ignored, but are accepted by the function | ||
* for compatibility with the WebSQL specification. | ||
* @param name Name of the database file to open. | ||
* @param version | ||
* @param description | ||
* @param size | ||
* @param callback | ||
* @return | ||
*/ | ||
export declare function openDatabase(name: string, version?: string, description?: string, size?: number, callback?: (db: WebSQLDatabase) => void): WebSQLDatabase; |
import './polyfillNextTick'; | ||
import customOpenDatabase from '@expo/websql/custom'; | ||
import { NativeModulesProxy } from '@unimodules/core'; | ||
import { NativeModulesProxy } from 'expo-modules-core'; | ||
import zipObject from 'lodash/zipObject'; | ||
@@ -8,4 +8,5 @@ import { Platform } from 'react-native'; | ||
class SQLiteDatabase { | ||
_name; | ||
_closed = false; | ||
constructor(name) { | ||
this._closed = false; | ||
this._name = name; | ||
@@ -17,5 +18,5 @@ } | ||
} | ||
ExponentSQLite.exec(this._name, queries.map(_serializeQuery), readOnly).then(nativeResultSets => { | ||
ExponentSQLite.exec(this._name, queries.map(_serializeQuery), readOnly).then((nativeResultSets) => { | ||
callback(null, nativeResultSets.map(_deserializeResultSet)); | ||
}, error => { | ||
}, (error) => { | ||
// TODO: make the native API consistently reject with an error, not a string or other type | ||
@@ -43,3 +44,3 @@ callback(error instanceof Error ? error : new Error(error)); | ||
rowsAffected, | ||
rows: rows.map(row => zipObject(columns, row)), | ||
rows: rows.map((row) => zipObject(columns, row)), | ||
}; | ||
@@ -67,2 +68,16 @@ } | ||
} | ||
// @needsAudit @docsMissing | ||
/** | ||
* Open a database, creating it if it doesn't exist, and return a `Database` object. On disk, | ||
* the database will be created under the app's [documents directory](../filesystem), i.e. | ||
* `${FileSystem.documentDirectory}/SQLite/${name}`. | ||
* > The `version`, `description` and `size` arguments are ignored, but are accepted by the function | ||
* for compatibility with the WebSQL specification. | ||
* @param name Name of the database file to open. | ||
* @param version | ||
* @param description | ||
* @param size | ||
* @param callback | ||
* @return | ||
*/ | ||
export function openDatabase(name, version = '1.0', description = name, size = 1, callback) { | ||
@@ -69,0 +84,0 @@ if (name === undefined) { |
export interface Window { | ||
openDatabase?: (name: string, version: string, displayName: string, estimatedSize: number, creationCallback?: DatabaseCallback) => Database; | ||
} | ||
export interface DatabaseCallback { | ||
(database: Database): void; | ||
} | ||
export declare type DatabaseCallback = (database: Database) => void; | ||
/** | ||
* `Database` objects are returned by calls to `SQLite.openDatabase()`. Such an object represents a | ||
* connection to a database on your device. | ||
*/ | ||
export interface Database { | ||
version: string; | ||
transaction(callback: SQLTransactionCallback, errorCallback?: SQLTransactionErrorCallback, successCallback?: SQLVoidCallback): void; | ||
readTransaction(callback: SQLTransactionCallback, errorCallback?: SQLTransactionErrorCallback, successCallback?: SQLVoidCallback): void; | ||
/** | ||
* Execute a database transaction. | ||
* @param callback A function representing the transaction to perform. Takes a Transaction | ||
* (see below) as its only parameter, on which it can add SQL statements to execute. | ||
* @param errorCallback Called if an error occurred processing this transaction. Takes a single | ||
* parameter describing the error. | ||
* @param successCallback Called when the transaction has completed executing on the database. | ||
*/ | ||
transaction(callback: SQLTransactionCallback, errorCallback?: SQLTransactionErrorCallback, successCallback?: () => void): void; | ||
readTransaction(callback: SQLTransactionCallback, errorCallback?: SQLTransactionErrorCallback, successCallback?: () => void): void; | ||
} | ||
export interface SQLVoidCallback { | ||
(): void; | ||
} | ||
export interface SQLTransactionCallback { | ||
(transaction: SQLTransaction): void; | ||
} | ||
export interface SQLTransactionErrorCallback { | ||
(error: SQLError): void; | ||
} | ||
export declare type SQLTransactionCallback = (transaction: SQLTransaction) => void; | ||
export declare type SQLTransactionErrorCallback = (error: SQLError) => void; | ||
/** | ||
* A `SQLTransaction` object is passed in as a parameter to the `callback` parameter for the | ||
* `db.transaction()` method on a `Database` (see above). It allows enqueuing SQL statements to | ||
* perform in a database transaction. | ||
*/ | ||
export interface SQLTransaction { | ||
executeSql(sqlStatement: string, args?: any[], callback?: SQLStatementCallback, errorCallback?: SQLStatementErrorCallback): void; | ||
/** | ||
* Enqueue a SQL statement to execute in the transaction. Authors are strongly recommended to make | ||
* use of the `?` placeholder feature of the method to avoid against SQL injection attacks, and to | ||
* never construct SQL statements on the fly. | ||
* @param sqlStatement A string containing a database query to execute expressed as SQL. The string | ||
* may contain `?` placeholders, with values to be substituted listed in the `arguments` parameter. | ||
* @param args An array of values (numbers or strings) to substitute for `?` placeholders in the | ||
* SQL statement. | ||
* @param callback Called when the query is successfully completed during the transaction. Takes | ||
* two parameters: the transaction itself, and a `ResultSet` object (see below) with the results | ||
* of the query. | ||
* @param errorCallback Called if an error occurred executing this particular query in the | ||
* transaction. Takes two parameters: the transaction itself, and the error object. | ||
*/ | ||
executeSql(sqlStatement: string, args?: (number | string)[], callback?: SQLStatementCallback, errorCallback?: SQLStatementErrorCallback): void; | ||
} | ||
export interface SQLStatementCallback { | ||
(transaction: SQLTransaction, resultSet: SQLResultSet): void; | ||
} | ||
export interface SQLStatementErrorCallback { | ||
(transaction: SQLTransaction, error: SQLError): boolean; | ||
} | ||
export interface SQLResultSet { | ||
insertId: number; | ||
export declare type SQLStatementCallback = (transaction: SQLTransaction, resultSet: SQLResultSet) => void; | ||
export declare type SQLStatementErrorCallback = (transaction: SQLTransaction, error: SQLError) => boolean; | ||
export declare type SQLResultSet = { | ||
/** | ||
* The row ID of the row that the SQL statement inserted into the database, if a row was inserted. | ||
*/ | ||
insertId?: number; | ||
/** | ||
* The number of rows that were changed by the SQL statement. | ||
*/ | ||
rowsAffected: number; | ||
rows: SQLResultSetRowList; | ||
} | ||
}; | ||
export interface SQLResultSetRowList { | ||
/** | ||
* The number of rows returned by the query. | ||
*/ | ||
length: number; | ||
/** | ||
* Returns the row with the given `index`. If there is no such row, returns `null`. | ||
* @param index Index of row to get. | ||
*/ | ||
item(index: number): any; | ||
/** | ||
* The actual array of rows returned by the query. Can be used directly instead of | ||
* getting rows through rows.item(). | ||
*/ | ||
_array: any[]; | ||
} | ||
@@ -58,7 +94,17 @@ export declare class SQLError { | ||
}; | ||
export interface ResultSetError { | ||
export declare type ResultSetError = { | ||
error: Error; | ||
} | ||
export interface ResultSet { | ||
}; | ||
/** | ||
* `ResultSet` objects are returned through second parameter of the `success` callback for the | ||
* `tx.executeSql()` method on a `SQLTransaction` (see above). | ||
*/ | ||
export declare type ResultSet = { | ||
/** | ||
* The row ID of the row that the SQL statement inserted into the database, if a row was inserted. | ||
*/ | ||
insertId?: number; | ||
/** | ||
* The number of rows that were changed by the SQL statement. | ||
*/ | ||
rowsAffected: number; | ||
@@ -68,3 +114,3 @@ rows: { | ||
}[]; | ||
} | ||
}; | ||
export declare type SQLiteCallback = (error?: Error | null, resultSet?: (ResultSetError | ResultSet)[]) => void; |
@@ -1,2 +0,2 @@ | ||
import { UnavailabilityError } from '@unimodules/core'; | ||
import { UnavailabilityError } from 'expo-modules-core'; | ||
export function openDatabase(name, version = '1.0', description = name, size = 1, callback) { | ||
@@ -3,0 +3,0 @@ const typedWindow = window; |
@@ -13,6 +13,17 @@ # Changelog | ||
## 9.2.1 — 2021-06-22 | ||
## 10.0.0 — 2021-09-28 | ||
_This version does not introduce any user-facing changes._ | ||
### 🛠 Breaking changes | ||
- Dropped support for iOS 11.0 ([#14383](https://github.com/expo/expo/pull/14383) by [@cruzach](https://github.com/cruzach)) | ||
### 🐛 Bug fixes | ||
- Fix building errors from use_frameworks! in Podfile. ([#14523](https://github.com/expo/expo/pull/14523) by [@kudo](https://github.com/kudo)) | ||
### 💡 Others | ||
- Converted Android code to Kotlin ([#13724](https://github.com/expo/expo/pull/13724) by [@ixf](https://github.com/ixf)) | ||
- Added missing `_array` typing to `SQLResultSetRowList`/`ResultSet` return object. ([#13826](https://github.com/expo/expo/pull/13826) by [@bbarthec](https://github.com/bbarthec)) | ||
## 9.2.0 — 2021-06-16 | ||
@@ -19,0 +30,0 @@ |
{ | ||
"name": "expo-sqlite", | ||
"version": "9.2.1", | ||
"version": "10.0.0", | ||
"description": "Provides access to a database that can be queried through a WebSQL-like API (https://www.w3.org/TR/webdatabase/). The database is persisted across restarts of your app.", | ||
@@ -34,3 +34,3 @@ "main": "build/index.js", | ||
"license": "MIT", | ||
"homepage": "https://docs.expo.io/versions/latest/sdk/sqlite/", | ||
"homepage": "https://docs.expo.dev/versions/latest/sdk/sqlite/", | ||
"jest": { | ||
@@ -41,3 +41,3 @@ "preset": "expo-module-scripts/ios" | ||
"@expo/websql": "^1.0.1", | ||
"expo-modules-core": "~0.2.0", | ||
"expo-modules-core": "~0.4.0", | ||
"lodash": "^4.17.15" | ||
@@ -49,3 +49,3 @@ }, | ||
}, | ||
"gitHead": "6e8cfadff90f106d6321d0dd8c4158f12a973d30" | ||
"gitHead": "1fffde73411ee7a642b98f1506a8de921805d52b" | ||
} |
import './polyfillNextTick'; | ||
import customOpenDatabase from '@expo/websql/custom'; | ||
import { NativeModulesProxy } from '@unimodules/core'; | ||
import { NativeModulesProxy } from 'expo-modules-core'; | ||
import zipObject from 'lodash/zipObject'; | ||
@@ -26,6 +26,6 @@ import { Platform } from 'react-native'; | ||
ExponentSQLite.exec(this._name, queries.map(_serializeQuery), readOnly).then( | ||
nativeResultSets => { | ||
(nativeResultSets) => { | ||
callback(null, nativeResultSets.map(_deserializeResultSet)); | ||
}, | ||
error => { | ||
(error) => { | ||
// TODO: make the native API consistently reject with an error, not a string or other type | ||
@@ -58,3 +58,3 @@ callback(error instanceof Error ? error : new Error(error)); | ||
rowsAffected, | ||
rows: rows.map(row => zipObject(columns, row)), | ||
rows: rows.map((row) => zipObject(columns, row)), | ||
}; | ||
@@ -85,2 +85,16 @@ } | ||
// @needsAudit @docsMissing | ||
/** | ||
* Open a database, creating it if it doesn't exist, and return a `Database` object. On disk, | ||
* the database will be created under the app's [documents directory](../filesystem), i.e. | ||
* `${FileSystem.documentDirectory}/SQLite/${name}`. | ||
* > The `version`, `description` and `size` arguments are ignored, but are accepted by the function | ||
* for compatibility with the WebSQL specification. | ||
* @param name Name of the database file to open. | ||
* @param version | ||
* @param description | ||
* @param size | ||
* @param callback | ||
* @return | ||
*/ | ||
export function openDatabase( | ||
@@ -87,0 +101,0 @@ name: string, |
@@ -8,2 +8,3 @@ // Definitions copied from `@types/websql` as we want | ||
// @docsMissing | ||
export interface Window { | ||
@@ -19,13 +20,25 @@ openDatabase?: ( | ||
export interface DatabaseCallback { | ||
(database: Database): void; | ||
} | ||
// @docsMissing | ||
export type DatabaseCallback = (database: Database) => void; | ||
// @needsAudit @docsMissing | ||
/** | ||
* `Database` objects are returned by calls to `SQLite.openDatabase()`. Such an object represents a | ||
* connection to a database on your device. | ||
*/ | ||
export interface Database { | ||
version: string; | ||
/** | ||
* Execute a database transaction. | ||
* @param callback A function representing the transaction to perform. Takes a Transaction | ||
* (see below) as its only parameter, on which it can add SQL statements to execute. | ||
* @param errorCallback Called if an error occurred processing this transaction. Takes a single | ||
* parameter describing the error. | ||
* @param successCallback Called when the transaction has completed executing on the database. | ||
*/ | ||
transaction( | ||
callback: SQLTransactionCallback, | ||
errorCallback?: SQLTransactionErrorCallback, | ||
successCallback?: SQLVoidCallback | ||
successCallback?: () => void | ||
): void; | ||
@@ -36,22 +49,36 @@ | ||
errorCallback?: SQLTransactionErrorCallback, | ||
successCallback?: SQLVoidCallback | ||
successCallback?: () => void | ||
): void; | ||
} | ||
export interface SQLVoidCallback { | ||
(): void; | ||
} | ||
// @docsMissing | ||
export type SQLTransactionCallback = (transaction: SQLTransaction) => void; | ||
export interface SQLTransactionCallback { | ||
(transaction: SQLTransaction): void; | ||
} | ||
// @docsMissing | ||
export type SQLTransactionErrorCallback = (error: SQLError) => void; | ||
export interface SQLTransactionErrorCallback { | ||
(error: SQLError): void; | ||
} | ||
// @needsAudit | ||
/** | ||
* A `SQLTransaction` object is passed in as a parameter to the `callback` parameter for the | ||
* `db.transaction()` method on a `Database` (see above). It allows enqueuing SQL statements to | ||
* perform in a database transaction. | ||
*/ | ||
export interface SQLTransaction { | ||
/** | ||
* Enqueue a SQL statement to execute in the transaction. Authors are strongly recommended to make | ||
* use of the `?` placeholder feature of the method to avoid against SQL injection attacks, and to | ||
* never construct SQL statements on the fly. | ||
* @param sqlStatement A string containing a database query to execute expressed as SQL. The string | ||
* may contain `?` placeholders, with values to be substituted listed in the `arguments` parameter. | ||
* @param args An array of values (numbers or strings) to substitute for `?` placeholders in the | ||
* SQL statement. | ||
* @param callback Called when the query is successfully completed during the transaction. Takes | ||
* two parameters: the transaction itself, and a `ResultSet` object (see below) with the results | ||
* of the query. | ||
* @param errorCallback Called if an error occurred executing this particular query in the | ||
* transaction. Takes two parameters: the transaction itself, and the error object. | ||
*/ | ||
executeSql( | ||
sqlStatement: string, | ||
args?: any[], | ||
args?: (number | string)[], | ||
callback?: SQLStatementCallback, | ||
@@ -62,21 +89,40 @@ errorCallback?: SQLStatementErrorCallback | ||
export interface SQLStatementCallback { | ||
(transaction: SQLTransaction, resultSet: SQLResultSet): void; | ||
} | ||
// @docsMissing | ||
export type SQLStatementCallback = (transaction: SQLTransaction, resultSet: SQLResultSet) => void; | ||
export interface SQLStatementErrorCallback { | ||
(transaction: SQLTransaction, error: SQLError): boolean; | ||
} | ||
// @docsMissing | ||
export type SQLStatementErrorCallback = (transaction: SQLTransaction, error: SQLError) => boolean; | ||
export interface SQLResultSet { | ||
insertId: number; | ||
// @needsAudit | ||
export type SQLResultSet = { | ||
/** | ||
* The row ID of the row that the SQL statement inserted into the database, if a row was inserted. | ||
*/ | ||
insertId?: number; | ||
/** | ||
* The number of rows that were changed by the SQL statement. | ||
*/ | ||
rowsAffected: number; | ||
rows: SQLResultSetRowList; | ||
} | ||
}; | ||
// @needsAudit | ||
export interface SQLResultSetRowList { | ||
/** | ||
* The number of rows returned by the query. | ||
*/ | ||
length: number; | ||
/** | ||
* Returns the row with the given `index`. If there is no such row, returns `null`. | ||
* @param index Index of row to get. | ||
*/ | ||
item(index: number): any; | ||
/** | ||
* The actual array of rows returned by the query. Can be used directly instead of | ||
* getting rows through rows.item(). | ||
*/ | ||
_array: any[]; | ||
} | ||
// @docsMissing | ||
export declare class SQLError { | ||
@@ -96,2 +142,3 @@ static UNKNOWN_ERR: number; | ||
// @docsMissing | ||
export interface WebSQLDatabase extends Database { | ||
@@ -101,13 +148,28 @@ exec(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void; | ||
// @docsMissing | ||
export type Query = { sql: string; args: unknown[] }; | ||
export interface ResultSetError { | ||
// @docsMissing | ||
export type ResultSetError = { | ||
error: Error; | ||
} | ||
export interface ResultSet { | ||
}; | ||
// @needsAudit | ||
/** | ||
* `ResultSet` objects are returned through second parameter of the `success` callback for the | ||
* `tx.executeSql()` method on a `SQLTransaction` (see above). | ||
*/ | ||
export type ResultSet = { | ||
/** | ||
* The row ID of the row that the SQL statement inserted into the database, if a row was inserted. | ||
*/ | ||
insertId?: number; | ||
/** | ||
* The number of rows that were changed by the SQL statement. | ||
*/ | ||
rowsAffected: number; | ||
rows: { [column: string]: any }[]; | ||
} | ||
}; | ||
// @docsMissing | ||
export type SQLiteCallback = ( | ||
@@ -114,0 +176,0 @@ error?: Error | null, |
@@ -1,2 +0,2 @@ | ||
import { UnavailabilityError } from '@unimodules/core'; | ||
import { UnavailabilityError } from 'expo-modules-core'; | ||
@@ -3,0 +3,0 @@ import { Window, DatabaseCallback } from './SQLite.types'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
58028
14.88%36
2.86%540
-25.41%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
Updated