expo-sqlite 10.1.0 → 10.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +3 -3
- package/android/build.gradle +41 -24
- package/android/src/main/java/expo/modules/sqlite/SQLiteModule.kt +18 -0
- package/build/SQLite.d.ts +2 -1
- package/build/SQLite.d.ts.map +1 -0
- package/build/SQLite.js +12 -10
- package/build/SQLite.js.map +1 -1
- package/build/SQLite.types.d.ts +12 -2
- package/build/SQLite.types.d.ts.map +1 -0
- package/build/SQLite.types.js.map +1 -1
- package/build/SQLite.web.d.ts +1 -0
- package/build/SQLite.web.d.ts.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -0
- package/build/polyfillNextTick.d.ts +1 -0
- package/build/polyfillNextTick.d.ts.map +1 -0
- package/ios/EXSQLite/EXSQLite.m +31 -0
- package/package.json +2 -2
- package/src/SQLite.ts +16 -11
- package/src/SQLite.types.ts +13 -2
- package/tsconfig.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,28 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 10.3.0 — 2022-07-07
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- Support `null` type in args to `executeSql`. ([#18078](https://github.com/expo/expo/pull/18078) by [@tsheaff](https://github.com/tsheaff))
|
|
18
|
+
|
|
19
|
+
## 10.2.0 — 2022-04-18
|
|
20
|
+
|
|
21
|
+
### 🎉 New features
|
|
22
|
+
|
|
23
|
+
- Added `closeAsync` and `deleteAsync` methods. ([#16831](https://github.com/expo/expo/pull/16831) by [@kudo](https://github.com/kudo))
|
|
24
|
+
|
|
25
|
+
### ⚠️ Notices
|
|
26
|
+
|
|
27
|
+
- On Android bump `compileSdkVersion` to `31`, `targetSdkVersion` to `31` and `Java` version to `11`. ([#16941](https://github.com/expo/expo/pull/16941) by [@bbarthec](https://github.com/bbarthec))
|
|
28
|
+
|
|
29
|
+
## 10.1.1 - 2022-02-01
|
|
30
|
+
|
|
31
|
+
### 🐛 Bug fixes
|
|
32
|
+
|
|
33
|
+
- Fix `Plugin with id 'maven' not found` build error from Android Gradle 7. ([#16080](https://github.com/expo/expo/pull/16080) by [@kudo](https://github.com/kudo))
|
|
34
|
+
|
|
13
35
|
## 10.1.0 — 2021-12-03
|
|
14
36
|
|
|
15
37
|
### 🎉 New features
|
package/README.md
CHANGED
|
@@ -4,12 +4,12 @@ Provides access to a database that can be queried through a WebSQL-like API (htt
|
|
|
4
4
|
|
|
5
5
|
# API documentation
|
|
6
6
|
|
|
7
|
-
- [Documentation for the
|
|
8
|
-
- [Documentation for the latest stable release](https://docs.expo.
|
|
7
|
+
- [Documentation for the main branch](https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/sqlite.md)
|
|
8
|
+
- [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/sqlite/)
|
|
9
9
|
|
|
10
10
|
# Installation in managed Expo projects
|
|
11
11
|
|
|
12
|
-
For
|
|
12
|
+
For [managed](https://docs.expo.dev/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/sqlite/).
|
|
13
13
|
|
|
14
14
|
# Installation in bare React Native projects
|
|
15
15
|
|
package/android/build.gradle
CHANGED
|
@@ -1,63 +1,80 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
2
|
apply plugin: 'kotlin-android'
|
|
3
|
-
apply plugin: 'maven'
|
|
3
|
+
apply plugin: 'maven-publish'
|
|
4
4
|
|
|
5
5
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '10.
|
|
6
|
+
version = '10.3.0'
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
9
|
+
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
10
|
+
if (expoModulesCorePlugin.exists()) {
|
|
11
|
+
apply from: expoModulesCorePlugin
|
|
12
|
+
applyKotlinExpoModulesCorePlugin()
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
// Simple helper that allows the root project to override versions declared by this library.
|
|
10
16
|
ext.safeExtGet = { prop, fallback ->
|
|
11
17
|
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
12
18
|
}
|
|
13
19
|
|
|
20
|
+
// Ensures backward compatibility
|
|
21
|
+
ext.getKotlinVersion = {
|
|
22
|
+
if (ext.has("kotlinVersion")) {
|
|
23
|
+
ext.kotlinVersion()
|
|
24
|
+
} else {
|
|
25
|
+
ext.safeExtGet("kotlinVersion", "1.6.10")
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
14
29
|
repositories {
|
|
15
30
|
mavenCentral()
|
|
16
31
|
}
|
|
17
32
|
|
|
18
33
|
dependencies {
|
|
19
|
-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${
|
|
34
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
|
|
20
35
|
}
|
|
21
36
|
}
|
|
22
37
|
|
|
23
|
-
// Upload android library to maven with javadoc and android sources
|
|
24
|
-
configurations {
|
|
25
|
-
deployerJars
|
|
26
|
-
}
|
|
27
|
-
|
|
28
38
|
// Creating sources with comments
|
|
29
39
|
task androidSourcesJar(type: Jar) {
|
|
30
40
|
classifier = 'sources'
|
|
31
41
|
from android.sourceSets.main.java.srcDirs
|
|
32
42
|
}
|
|
33
43
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
afterEvaluate {
|
|
45
|
+
publishing {
|
|
46
|
+
publications {
|
|
47
|
+
release(MavenPublication) {
|
|
48
|
+
from components.release
|
|
49
|
+
// Add additional sourcesJar to artifacts
|
|
50
|
+
artifact(androidSourcesJar)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
repositories {
|
|
54
|
+
maven {
|
|
55
|
+
url = mavenLocal().url
|
|
56
|
+
}
|
|
44
57
|
}
|
|
45
58
|
}
|
|
46
59
|
}
|
|
47
60
|
|
|
48
61
|
android {
|
|
49
|
-
compileSdkVersion safeExtGet("compileSdkVersion",
|
|
62
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 31)
|
|
50
63
|
|
|
51
64
|
compileOptions {
|
|
52
|
-
sourceCompatibility JavaVersion.
|
|
53
|
-
targetCompatibility JavaVersion.
|
|
65
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
66
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
kotlinOptions {
|
|
70
|
+
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
54
71
|
}
|
|
55
72
|
|
|
56
73
|
defaultConfig {
|
|
57
74
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
58
|
-
targetSdkVersion safeExtGet("targetSdkVersion",
|
|
75
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 31)
|
|
59
76
|
versionCode 18
|
|
60
|
-
versionName "10.
|
|
77
|
+
versionName "10.3.0"
|
|
61
78
|
}
|
|
62
79
|
lintOptions {
|
|
63
80
|
abortOnError false
|
|
@@ -67,5 +84,5 @@ android {
|
|
|
67
84
|
dependencies {
|
|
68
85
|
implementation project(':expo-modules-core')
|
|
69
86
|
|
|
70
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${
|
|
87
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
71
88
|
}
|
|
@@ -58,6 +58,24 @@ class SQLiteModule(private val mContext: Context) : ExportedModule(mContext) {
|
|
|
58
58
|
promise.resolve(null)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
@ExpoMethod
|
|
62
|
+
fun deleteAsync(dbName: String, promise: Promise) {
|
|
63
|
+
val errorCode = "SQLiteError"
|
|
64
|
+
if (DATABASES.containsKey(dbName)) {
|
|
65
|
+
promise.reject(errorCode, "Unable to delete database '$dbName' that is currently open. Close it prior to deletion.")
|
|
66
|
+
}
|
|
67
|
+
val dbFile = File(pathForDatabaseName(dbName))
|
|
68
|
+
if (!dbFile.exists()) {
|
|
69
|
+
promise.reject(errorCode, "Database '$dbName' not found")
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
if (!dbFile.delete()) {
|
|
73
|
+
promise.reject(errorCode, "Unable to delete the database file for '$dbName' database")
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
promise.resolve(null)
|
|
77
|
+
}
|
|
78
|
+
|
|
61
79
|
// do a update/delete/insert operation
|
|
62
80
|
private fun doUpdateInBackgroundAndPossiblyThrow(
|
|
63
81
|
sql: String,
|
package/build/SQLite.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import './polyfillNextTick';
|
|
|
2
2
|
import { WebSQLDatabase } from './SQLite.types';
|
|
3
3
|
/**
|
|
4
4
|
* Open a database, creating it if it doesn't exist, and return a `Database` object. On disk,
|
|
5
|
-
* the database will be created under the app's [documents directory](
|
|
5
|
+
* the database will be created under the app's [documents directory](./filesystem), i.e.
|
|
6
6
|
* `${FileSystem.documentDirectory}/SQLite/${name}`.
|
|
7
7
|
* > The `version`, `description` and `size` arguments are ignored, but are accepted by the function
|
|
8
8
|
* for compatibility with the WebSQL specification.
|
|
@@ -14,3 +14,4 @@ import { WebSQLDatabase } from './SQLite.types';
|
|
|
14
14
|
* @return
|
|
15
15
|
*/
|
|
16
16
|
export declare function openDatabase(name: string, version?: string, description?: string, size?: number, callback?: (db: WebSQLDatabase) => void): WebSQLDatabase;
|
|
17
|
+
//# sourceMappingURL=SQLite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SQLite.d.ts","sourceRoot":"","sources":["../src/SQLite.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAM5B,OAAO,EAAoD,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAuFlG;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAc,EACvB,WAAW,GAAE,MAAa,EAC1B,IAAI,GAAE,MAAU,EAChB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,cAAc,KAAK,IAAI,GACtC,cAAc,CAShB"}
|
package/build/SQLite.js
CHANGED
|
@@ -29,7 +29,13 @@ class SQLiteDatabase {
|
|
|
29
29
|
}
|
|
30
30
|
close() {
|
|
31
31
|
this._closed = true;
|
|
32
|
-
ExponentSQLite.close(this._name);
|
|
32
|
+
return ExponentSQLite.close(this._name);
|
|
33
|
+
}
|
|
34
|
+
deleteAsync() {
|
|
35
|
+
if (!this._closed) {
|
|
36
|
+
throw new Error(`Unable to delete '${this._name}' database that is currently open. Close it prior to deletion.`);
|
|
37
|
+
}
|
|
38
|
+
return ExponentSQLite.deleteAsync(this._name);
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
41
|
function _serializeQuery(query) {
|
|
@@ -62,16 +68,10 @@ function _escapeBlob(data) {
|
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
const _openExpoSQLiteDatabase = customOpenDatabase(SQLiteDatabase);
|
|
65
|
-
function addExecMethod(db) {
|
|
66
|
-
db.exec = (queries, readOnly, callback) => {
|
|
67
|
-
db._db.exec(queries, readOnly, callback);
|
|
68
|
-
};
|
|
69
|
-
return db;
|
|
70
|
-
}
|
|
71
71
|
// @needsAudit @docsMissing
|
|
72
72
|
/**
|
|
73
73
|
* Open a database, creating it if it doesn't exist, and return a `Database` object. On disk,
|
|
74
|
-
* the database will be created under the app's [documents directory](
|
|
74
|
+
* the database will be created under the app's [documents directory](./filesystem), i.e.
|
|
75
75
|
* `${FileSystem.documentDirectory}/SQLite/${name}`.
|
|
76
76
|
* > The `version`, `description` and `size` arguments are ignored, but are accepted by the function
|
|
77
77
|
* for compatibility with the WebSQL specification.
|
|
@@ -87,7 +87,9 @@ export function openDatabase(name, version = '1.0', description = name, size = 1
|
|
|
87
87
|
throw new TypeError(`The database name must not be undefined`);
|
|
88
88
|
}
|
|
89
89
|
const db = _openExpoSQLiteDatabase(name, version, description, size, callback);
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
db.exec = db._db.exec.bind(db._db);
|
|
91
|
+
db.closeAsync = db._db.close.bind(db._db);
|
|
92
|
+
db.deleteAsync = db._db.deleteAsync.bind(db._db);
|
|
93
|
+
return db;
|
|
92
94
|
}
|
|
93
95
|
//# sourceMappingURL=SQLite.js.map
|
package/build/SQLite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SQLite.js","sourceRoot":"","sources":["../src/SQLite.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAE5B,OAAO,kBAAkB,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAIxC,MAAM,EAAE,cAAc,EAAE,GAAG,kBAAkB,CAAC;AAE9C,SAAS,SAAS,CAAC,IAAc,EAAE,MAAa;IAC9C,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACpC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;KAC7B;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,cAAc;IAClB,KAAK,CAAS;IACd,OAAO,GAAY,KAAK,CAAC;IAEzB,YAAY,IAAY;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IA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AuB,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC/E,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACnC,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAC1C,EAAE,CAAC,WAAW,GAAG,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACjD,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import './polyfillNextTick';\n\nimport customOpenDatabase from '@expo/websql/custom';\nimport { NativeModulesProxy } from 'expo-modules-core';\nimport { Platform } from 'react-native';\n\nimport { Query, ResultSet, ResultSetError, SQLiteCallback, WebSQLDatabase } from './SQLite.types';\n\nconst { ExponentSQLite } = NativeModulesProxy;\n\nfunction zipObject(keys: string[], values: any[]) {\n const result = {};\n for (let i = 0; i < keys.length; i++) {\n result[keys[i]] = values[i];\n }\n return result;\n}\n\nclass SQLiteDatabase {\n _name: string;\n _closed: boolean = false;\n\n constructor(name: string) {\n this._name = name;\n }\n\n exec(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void {\n if (this._closed) {\n throw new Error(`The SQLite database is closed`);\n }\n\n ExponentSQLite.exec(this._name, queries.map(_serializeQuery), readOnly).then(\n (nativeResultSets) => {\n callback(null, nativeResultSets.map(_deserializeResultSet));\n },\n (error) => {\n // TODO: make the native API consistently reject with an error, not a string or other type\n callback(error instanceof Error ? error : new Error(error));\n }\n );\n }\n\n close() {\n this._closed = true;\n return ExponentSQLite.close(this._name);\n }\n\n deleteAsync(): Promise<void> {\n if (!this._closed) {\n throw new Error(\n `Unable to delete '${this._name}' database that is currently open. Close it prior to deletion.`\n );\n }\n\n return ExponentSQLite.deleteAsync(this._name);\n }\n}\n\nfunction _serializeQuery(query: Query): [string, unknown[]] {\n return [query.sql, Platform.OS === 'android' ? query.args.map(_escapeBlob) : query.args];\n}\n\nfunction _deserializeResultSet(nativeResult): ResultSet | ResultSetError {\n const [errorMessage, insertId, rowsAffected, columns, rows] = nativeResult;\n // TODO: send more structured error information from the native module so we can better construct\n // a SQLException object\n if (errorMessage !== null) {\n return { error: new Error(errorMessage) } as ResultSetError;\n }\n\n return {\n insertId,\n rowsAffected,\n rows: rows.map((row) => zipObject(columns, row)),\n };\n}\n\nfunction _escapeBlob<T>(data: T): T {\n if (typeof data === 'string') {\n /* eslint-disable no-control-regex */\n return data\n .replace(/\\u0002/g, '\\u0002\\u0002')\n .replace(/\\u0001/g, '\\u0001\\u0002')\n .replace(/\\u0000/g, '\\u0001\\u0001') as any;\n /* eslint-enable no-control-regex */\n } else {\n return data;\n }\n}\n\nconst _openExpoSQLiteDatabase = customOpenDatabase(SQLiteDatabase);\n\n// @needsAudit @docsMissing\n/**\n * Open a database, creating it if it doesn't exist, and return a `Database` object. On disk,\n * the database will be created under the app's [documents directory](./filesystem), i.e.\n * `${FileSystem.documentDirectory}/SQLite/${name}`.\n * > The `version`, `description` and `size` arguments are ignored, but are accepted by the function\n * for compatibility with the WebSQL specification.\n * @param name Name of the database file to open.\n * @param version\n * @param description\n * @param size\n * @param callback\n * @return\n */\nexport function openDatabase(\n name: string,\n version: string = '1.0',\n description: string = name,\n size: number = 1,\n callback?: (db: WebSQLDatabase) => void\n): WebSQLDatabase {\n if (name === undefined) {\n throw new TypeError(`The database name must not be undefined`);\n }\n const db = _openExpoSQLiteDatabase(name, version, description, size, callback);\n db.exec = db._db.exec.bind(db._db);\n db.closeAsync = db._db.close.bind(db._db);\n db.deleteAsync = db._db.deleteAsync.bind(db._db);\n return db;\n}\n"]}
|
package/build/SQLite.types.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface SQLTransaction {
|
|
|
33
33
|
* never construct SQL statements on the fly.
|
|
34
34
|
* @param sqlStatement A string containing a database query to execute expressed as SQL. The string
|
|
35
35
|
* may contain `?` placeholders, with values to be substituted listed in the `arguments` parameter.
|
|
36
|
-
* @param args An array of values (numbers or
|
|
36
|
+
* @param args An array of values (numbers, strings or nulls) to substitute for `?` placeholders in the
|
|
37
37
|
* SQL statement.
|
|
38
38
|
* @param callback Called when the query is successfully completed during the transaction. Takes
|
|
39
39
|
* two parameters: the transaction itself, and a `ResultSet` object (see below) with the results
|
|
@@ -41,7 +41,7 @@ export interface SQLTransaction {
|
|
|
41
41
|
* @param errorCallback Called if an error occurred executing this particular query in the
|
|
42
42
|
* transaction. Takes two parameters: the transaction itself, and the error object.
|
|
43
43
|
*/
|
|
44
|
-
executeSql(sqlStatement: string, args?: (number | string)[], callback?: SQLStatementCallback, errorCallback?: SQLStatementErrorCallback): void;
|
|
44
|
+
executeSql(sqlStatement: string, args?: (number | string | null)[], callback?: SQLStatementCallback, errorCallback?: SQLStatementErrorCallback): void;
|
|
45
45
|
}
|
|
46
46
|
export declare type SQLStatementCallback = (transaction: SQLTransaction, resultSet: SQLResultSet) => void;
|
|
47
47
|
export declare type SQLStatementErrorCallback = (transaction: SQLTransaction, error: SQLError) => boolean;
|
|
@@ -86,6 +86,15 @@ export declare class SQLError {
|
|
|
86
86
|
}
|
|
87
87
|
export interface WebSQLDatabase extends Database {
|
|
88
88
|
exec(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void;
|
|
89
|
+
/**
|
|
90
|
+
* Close the database.
|
|
91
|
+
*/
|
|
92
|
+
closeAsync(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Delete the database file.
|
|
95
|
+
* > The database has to be closed prior to deletion.
|
|
96
|
+
*/
|
|
97
|
+
deleteAsync(): Promise<void>;
|
|
89
98
|
}
|
|
90
99
|
export declare type Query = {
|
|
91
100
|
sql: string;
|
|
@@ -112,3 +121,4 @@ export declare type ResultSet = {
|
|
|
112
121
|
}[];
|
|
113
122
|
};
|
|
114
123
|
export declare type SQLiteCallback = (error?: Error | null, resultSet?: (ResultSetError | ResultSet)[]) => void;
|
|
124
|
+
//# sourceMappingURL=SQLite.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SQLite.types.d.ts","sourceRoot":"","sources":["../src/SQLite.types.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,MAAM;IACrB,YAAY,CAAC,EAAE,CACb,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,gBAAgB,CAAC,EAAE,gBAAgB,KAChC,QAAQ,CAAC;CACf;AAGD,oBAAY,gBAAgB,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;AAG5D;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;;OAOG;IACH,WAAW,CACT,QAAQ,EAAE,sBAAsB,EAChC,aAAa,CAAC,EAAE,2BAA2B,EAC3C,eAAe,CAAC,EAAE,MAAM,IAAI,GAC3B,IAAI,CAAC;IAER,eAAe,CACb,QAAQ,EAAE,sBAAsB,EAChC,aAAa,CAAC,EAAE,2BAA2B,EAC3C,eAAe,CAAC,EAAE,MAAM,IAAI,GAC3B,IAAI,CAAC;CACT;AAGD,oBAAY,sBAAsB,GAAG,CAAC,WAAW,EAAE,cAAc,KAAK,IAAI,CAAC;AAG3E,oBAAY,2BAA2B,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;AAGpE;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;;;;;OAaG;IACH,UAAU,CACR,YAAY,EAAE,MAAM,EACpB,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,EAAE,EACjC,QAAQ,CAAC,EAAE,oBAAoB,EAC/B,aAAa,CAAC,EAAE,yBAAyB,GACxC,IAAI,CAAC;CACT;AAGD,o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C,CAAC;CAC9B;AAGD,oBAAY,KAAK,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC;AAGrD,oBAAY,cAAc,GAAG;IAC3B,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAGF;;;GAGG;AACH,oBAAY,SAAS,GAAG;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,CAAC;CACnC,CAAC;AAGF,oBAAY,cAAc,GAAG,CAC3B,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,EACpB,SAAS,CAAC,EAAE,CAAC,cAAc,GAAG,SAAS,CAAC,EAAE,KACvC,IAAI,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SQLite.types.js","sourceRoot":"","sources":["../src/SQLite.types.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,8CAA8C;AAC9C,gDAAgD;AAChD,2DAA2D;AAC3D,EAAE;AACF,0EAA0E","sourcesContent":["// Definitions copied from `@types/websql` as we want\n// to expose a custom version of the API that:\n// - uses primitive `string` instead of `String`\n// - excludes some methods that are not exposed by our API.\n//\n// Original definitions by: TeamworkGuy2 <https://github.com/TeamworkGuy2>\n\n// @docsMissing\nexport interface Window {\n openDatabase?: (\n name: string,\n version: string,\n displayName: string,\n estimatedSize: number,\n creationCallback?: DatabaseCallback\n ) => Database;\n}\n\n// @docsMissing\nexport type DatabaseCallback = (database: Database) => void;\n\n// @needsAudit @docsMissing\n/**\n * `Database` objects are returned by calls to `SQLite.openDatabase()`. Such an object represents a\n * connection to a database on your device.\n */\nexport interface Database {\n version: string;\n\n /**\n * Execute a database transaction.\n * @param callback A function representing the transaction to perform. Takes a Transaction\n * (see below) as its only parameter, on which it can add SQL statements to execute.\n * @param errorCallback Called if an error occurred processing this transaction. Takes a single\n * parameter describing the error.\n * @param successCallback Called when the transaction has completed executing on the database.\n */\n transaction(\n callback: SQLTransactionCallback,\n errorCallback?: SQLTransactionErrorCallback,\n successCallback?: () => void\n ): void;\n\n readTransaction(\n callback: SQLTransactionCallback,\n errorCallback?: SQLTransactionErrorCallback,\n successCallback?: () => void\n ): void;\n}\n\n// @docsMissing\nexport type SQLTransactionCallback = (transaction: SQLTransaction) => void;\n\n// @docsMissing\nexport type SQLTransactionErrorCallback = (error: SQLError) => void;\n\n// @needsAudit\n/**\n * A `SQLTransaction` object is passed in as a parameter to the `callback` parameter for the\n * `db.transaction()` method on a `Database` (see above). It allows enqueuing SQL statements to\n * perform in a database transaction.\n */\nexport interface SQLTransaction {\n /**\n * Enqueue a SQL statement to execute in the transaction. Authors are strongly recommended to make\n * use of the `?` placeholder feature of the method to avoid against SQL injection attacks, and to\n * never construct SQL statements on the fly.\n * @param sqlStatement A string containing a database query to execute expressed as SQL. The string\n * may contain `?` placeholders, with values to be substituted listed in the `arguments` parameter.\n * @param args An array of values (numbers or
|
|
1
|
+
{"version":3,"file":"SQLite.types.js","sourceRoot":"","sources":["../src/SQLite.types.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,8CAA8C;AAC9C,gDAAgD;AAChD,2DAA2D;AAC3D,EAAE;AACF,0EAA0E","sourcesContent":["// Definitions copied from `@types/websql` as we want\n// to expose a custom version of the API that:\n// - uses primitive `string` instead of `String`\n// - excludes some methods that are not exposed by our API.\n//\n// Original definitions by: TeamworkGuy2 <https://github.com/TeamworkGuy2>\n\n// @docsMissing\nexport interface Window {\n openDatabase?: (\n name: string,\n version: string,\n displayName: string,\n estimatedSize: number,\n creationCallback?: DatabaseCallback\n ) => Database;\n}\n\n// @docsMissing\nexport type DatabaseCallback = (database: Database) => void;\n\n// @needsAudit @docsMissing\n/**\n * `Database` objects are returned by calls to `SQLite.openDatabase()`. Such an object represents a\n * connection to a database on your device.\n */\nexport interface Database {\n version: string;\n\n /**\n * Execute a database transaction.\n * @param callback A function representing the transaction to perform. Takes a Transaction\n * (see below) as its only parameter, on which it can add SQL statements to execute.\n * @param errorCallback Called if an error occurred processing this transaction. Takes a single\n * parameter describing the error.\n * @param successCallback Called when the transaction has completed executing on the database.\n */\n transaction(\n callback: SQLTransactionCallback,\n errorCallback?: SQLTransactionErrorCallback,\n successCallback?: () => void\n ): void;\n\n readTransaction(\n callback: SQLTransactionCallback,\n errorCallback?: SQLTransactionErrorCallback,\n successCallback?: () => void\n ): void;\n}\n\n// @docsMissing\nexport type SQLTransactionCallback = (transaction: SQLTransaction) => void;\n\n// @docsMissing\nexport type SQLTransactionErrorCallback = (error: SQLError) => void;\n\n// @needsAudit\n/**\n * A `SQLTransaction` object is passed in as a parameter to the `callback` parameter for the\n * `db.transaction()` method on a `Database` (see above). It allows enqueuing SQL statements to\n * perform in a database transaction.\n */\nexport interface SQLTransaction {\n /**\n * Enqueue a SQL statement to execute in the transaction. Authors are strongly recommended to make\n * use of the `?` placeholder feature of the method to avoid against SQL injection attacks, and to\n * never construct SQL statements on the fly.\n * @param sqlStatement A string containing a database query to execute expressed as SQL. The string\n * may contain `?` placeholders, with values to be substituted listed in the `arguments` parameter.\n * @param args An array of values (numbers, strings or nulls) to substitute for `?` placeholders in the\n * SQL statement.\n * @param callback Called when the query is successfully completed during the transaction. Takes\n * two parameters: the transaction itself, and a `ResultSet` object (see below) with the results\n * of the query.\n * @param errorCallback Called if an error occurred executing this particular query in the\n * transaction. Takes two parameters: the transaction itself, and the error object.\n */\n executeSql(\n sqlStatement: string,\n args?: (number | string | null)[],\n callback?: SQLStatementCallback,\n errorCallback?: SQLStatementErrorCallback\n ): void;\n}\n\n// @docsMissing\nexport type SQLStatementCallback = (transaction: SQLTransaction, resultSet: SQLResultSet) => void;\n\n// @docsMissing\nexport type SQLStatementErrorCallback = (transaction: SQLTransaction, error: SQLError) => boolean;\n\n// @needsAudit\nexport type SQLResultSet = {\n /**\n * The row ID of the row that the SQL statement inserted into the database, if a row was inserted.\n */\n insertId?: number;\n /**\n * The number of rows that were changed by the SQL statement.\n */\n rowsAffected: number;\n rows: SQLResultSetRowList;\n};\n\n// @needsAudit\nexport interface SQLResultSetRowList {\n /**\n * The number of rows returned by the query.\n */\n length: number;\n /**\n * Returns the row with the given `index`. If there is no such row, returns `null`.\n * @param index Index of row to get.\n */\n item(index: number): any;\n /**\n * The actual array of rows returned by the query. Can be used directly instead of\n * getting rows through rows.item().\n */\n _array: any[];\n}\n\n// @docsMissing\nexport declare class SQLError {\n static UNKNOWN_ERR: number;\n static DATABASE_ERR: number;\n static VERSION_ERR: number;\n static TOO_LARGE_ERR: number;\n static QUOTA_ERR: number;\n static SYNTAX_ERR: number;\n static CONSTRAINT_ERR: number;\n static TIMEOUT_ERR: number;\n\n code: number;\n message: string;\n}\n\n// @docsMissing\nexport interface WebSQLDatabase extends Database {\n exec(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void;\n\n /**\n * Close the database.\n */\n closeAsync(): void;\n\n /**\n * Delete the database file.\n * > The database has to be closed prior to deletion.\n */\n deleteAsync(): Promise<void>;\n}\n\n// @docsMissing\nexport type Query = { sql: string; args: unknown[] };\n\n// @docsMissing\nexport type ResultSetError = {\n error: Error;\n};\n\n// @needsAudit\n/**\n * `ResultSet` objects are returned through second parameter of the `success` callback for the\n * `tx.executeSql()` method on a `SQLTransaction` (see above).\n */\nexport type ResultSet = {\n /**\n * The row ID of the row that the SQL statement inserted into the database, if a row was inserted.\n */\n insertId?: number;\n /**\n * The number of rows that were changed by the SQL statement.\n */\n rowsAffected: number;\n rows: { [column: string]: any }[];\n};\n\n// @docsMissing\nexport type SQLiteCallback = (\n error?: Error | null,\n resultSet?: (ResultSetError | ResultSet)[]\n) => void;\n"]}
|
package/build/SQLite.web.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SQLite.web.d.ts","sourceRoot":"","sources":["../src/SQLite.web.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAc,EACvB,WAAW,GAAE,MAAa,EAC1B,IAAI,GAAE,MAAU,EAChB,QAAQ,CAAC,EAAE,gBAAgB,qCAO5B"}
|
package/build/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfillNextTick.d.ts","sourceRoot":"","sources":["../src/polyfillNextTick.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/ios/EXSQLite/EXSQLite.m
CHANGED
|
@@ -100,6 +100,37 @@ EX_EXPORT_METHOD_AS(close,
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
EX_EXPORT_METHOD_AS(deleteAsync,
|
|
104
|
+
deleteDbName:(NSString *)dbName
|
|
105
|
+
resolver:(EXPromiseResolveBlock)resolve
|
|
106
|
+
rejecter:(EXPromiseRejectBlock)reject)
|
|
107
|
+
{
|
|
108
|
+
NSString *errorCode = @"E_SQLITE_DELETE_DATABASE";
|
|
109
|
+
|
|
110
|
+
@synchronized(self) {
|
|
111
|
+
if ([cachedDatabases objectForKey:dbName]) {
|
|
112
|
+
reject(errorCode, [NSString stringWithFormat:@"Unable to delete database '%@' that is currently open. Close it prior to deletion.", dbName], nil);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
NSString *path = [self pathForDatabaseName:dbName];
|
|
118
|
+
if (!path) {
|
|
119
|
+
reject(errorCode, @"No FileSystem module.", nil);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
|
|
123
|
+
reject(errorCode, [NSString stringWithFormat:@"Database '%@' not found", dbName], nil);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
NSError *error;
|
|
127
|
+
if (![[NSFileManager defaultManager] removeItemAtPath:path error:&error]) {
|
|
128
|
+
reject(errorCode, [NSString stringWithFormat:@"Unable to delete the database file for '%@' database", dbName], error);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
resolve(nil);
|
|
132
|
+
}
|
|
133
|
+
|
|
103
134
|
- (id)getSqlValueForColumnType:(int)columnType withStatement:(sqlite3_stmt*)statement withIndex:(int)i
|
|
104
135
|
{
|
|
105
136
|
switch (columnType) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-sqlite",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.3.0",
|
|
4
4
|
"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.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"expo": "*"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "6e131f2da851a47c3a24eb3d6fc971a1a7822086"
|
|
48
48
|
}
|
package/src/SQLite.ts
CHANGED
|
@@ -42,7 +42,17 @@ class SQLiteDatabase {
|
|
|
42
42
|
|
|
43
43
|
close() {
|
|
44
44
|
this._closed = true;
|
|
45
|
-
ExponentSQLite.close(this._name);
|
|
45
|
+
return ExponentSQLite.close(this._name);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
deleteAsync(): Promise<void> {
|
|
49
|
+
if (!this._closed) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Unable to delete '${this._name}' database that is currently open. Close it prior to deletion.`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return ExponentSQLite.deleteAsync(this._name);
|
|
46
56
|
}
|
|
47
57
|
}
|
|
48
58
|
|
|
@@ -80,17 +90,10 @@ function _escapeBlob<T>(data: T): T {
|
|
|
80
90
|
|
|
81
91
|
const _openExpoSQLiteDatabase = customOpenDatabase(SQLiteDatabase);
|
|
82
92
|
|
|
83
|
-
function addExecMethod(db: any): WebSQLDatabase {
|
|
84
|
-
db.exec = (queries: Query[], readOnly: boolean, callback: SQLiteCallback): void => {
|
|
85
|
-
db._db.exec(queries, readOnly, callback);
|
|
86
|
-
};
|
|
87
|
-
return db;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
93
|
// @needsAudit @docsMissing
|
|
91
94
|
/**
|
|
92
95
|
* Open a database, creating it if it doesn't exist, and return a `Database` object. On disk,
|
|
93
|
-
* the database will be created under the app's [documents directory](
|
|
96
|
+
* the database will be created under the app's [documents directory](./filesystem), i.e.
|
|
94
97
|
* `${FileSystem.documentDirectory}/SQLite/${name}`.
|
|
95
98
|
* > The `version`, `description` and `size` arguments are ignored, but are accepted by the function
|
|
96
99
|
* for compatibility with the WebSQL specification.
|
|
@@ -112,6 +115,8 @@ export function openDatabase(
|
|
|
112
115
|
throw new TypeError(`The database name must not be undefined`);
|
|
113
116
|
}
|
|
114
117
|
const db = _openExpoSQLiteDatabase(name, version, description, size, callback);
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
db.exec = db._db.exec.bind(db._db);
|
|
119
|
+
db.closeAsync = db._db.close.bind(db._db);
|
|
120
|
+
db.deleteAsync = db._db.deleteAsync.bind(db._db);
|
|
121
|
+
return db;
|
|
117
122
|
}
|
package/src/SQLite.types.ts
CHANGED
|
@@ -67,7 +67,7 @@ export interface SQLTransaction {
|
|
|
67
67
|
* never construct SQL statements on the fly.
|
|
68
68
|
* @param sqlStatement A string containing a database query to execute expressed as SQL. The string
|
|
69
69
|
* may contain `?` placeholders, with values to be substituted listed in the `arguments` parameter.
|
|
70
|
-
* @param args An array of values (numbers or
|
|
70
|
+
* @param args An array of values (numbers, strings or nulls) to substitute for `?` placeholders in the
|
|
71
71
|
* SQL statement.
|
|
72
72
|
* @param callback Called when the query is successfully completed during the transaction. Takes
|
|
73
73
|
* two parameters: the transaction itself, and a `ResultSet` object (see below) with the results
|
|
@@ -77,7 +77,7 @@ export interface SQLTransaction {
|
|
|
77
77
|
*/
|
|
78
78
|
executeSql(
|
|
79
79
|
sqlStatement: string,
|
|
80
|
-
args?: (number | string)[],
|
|
80
|
+
args?: (number | string | null)[],
|
|
81
81
|
callback?: SQLStatementCallback,
|
|
82
82
|
errorCallback?: SQLStatementErrorCallback
|
|
83
83
|
): void;
|
|
@@ -138,6 +138,17 @@ export declare class SQLError {
|
|
|
138
138
|
// @docsMissing
|
|
139
139
|
export interface WebSQLDatabase extends Database {
|
|
140
140
|
exec(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Close the database.
|
|
144
|
+
*/
|
|
145
|
+
closeAsync(): void;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Delete the database file.
|
|
149
|
+
* > The database has to be closed prior to deletion.
|
|
150
|
+
*/
|
|
151
|
+
deleteAsync(): Promise<void>;
|
|
141
152
|
}
|
|
142
153
|
|
|
143
154
|
// @docsMissing
|
package/tsconfig.json
CHANGED