expo-sqlite 10.0.3 → 10.2.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 CHANGED
@@ -10,13 +10,31 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 10.0.32021-10-21
13
+ ## 10.2.0 — 2022-04-18
14
14
 
15
- _This version does not introduce any user-facing changes._
15
+ ### 🎉 New features
16
16
 
17
- ## 10.0.2 2021-10-15
17
+ - Added `closeAsync` and `deleteAsync` methods. ([#16831](https://github.com/expo/expo/pull/16831) by [@kudo](https://github.com/kudo))
18
18
 
19
- _This version does not introduce any user-facing changes._
19
+ ### ⚠️ Notices
20
+
21
+ - 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))
22
+
23
+ ## 10.1.1 - 2022-02-01
24
+
25
+ ### 🐛 Bug fixes
26
+
27
+ - 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))
28
+
29
+ ## 10.1.0 — 2021-12-03
30
+
31
+ ### 🎉 New features
32
+
33
+ - Removed lodash. ([#12523](https://github.com/expo/expo/pull/12523) by [@EvanBacon](https://github.com/EvanBacon))
34
+
35
+ ### 💡 Others
36
+
37
+ - Update `lodash` dependency. ([#15069](https://github.com/expo/expo/pull/15069) by [@Simek](https://github.com/Simek))
20
38
 
21
39
  ## 10.0.1 — 2021-10-01
22
40
 
package/README.md CHANGED
@@ -4,16 +4,16 @@ 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 master branch](https://github.com/expo/expo/blob/master/docs/pages/versions/unversioned/sdk/sqlite.md)
8
- - [Documentation for the latest stable release](https://docs.expo.io/versions/latest/sdk/sqlite/)
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 managed [managed](https://docs.expo.io/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.io/versions/latest/sdk/sqlite/).
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
 
16
- For bare React Native projects, you must ensure that you have [installed and configured the `react-native-unimodules` package](https://github.com/expo/expo/tree/master/packages/react-native-unimodules) before continuing.
16
+ For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
17
17
 
18
18
  ### Add the package to your npm dependencies
19
19
 
@@ -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.0.3'
6
+ version = '10.2.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:${safeExtGet('kotlinVersion', '1.4.21')}")
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
- // Put the androidSources and javadoc to the artifacts
35
- artifacts {
36
- archives androidSourcesJar
37
- }
38
-
39
- uploadArchives {
40
- repositories {
41
- mavenDeployer {
42
- configuration = configurations.deployerJars
43
- repository(url: mavenLocal().url)
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", 30)
62
+ compileSdkVersion safeExtGet("compileSdkVersion", 31)
50
63
 
51
64
  compileOptions {
52
- sourceCompatibility JavaVersion.VERSION_1_8
53
- targetCompatibility JavaVersion.VERSION_1_8
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", 30)
75
+ targetSdkVersion safeExtGet("targetSdkVersion", 31)
59
76
  versionCode 18
60
- versionName "10.0.3"
77
+ versionName "10.2.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:${safeExtGet('kotlinVersion', '1.4.21')}"
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](../filesystem), i.e.
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
@@ -1,9 +1,15 @@
1
1
  import './polyfillNextTick';
2
2
  import customOpenDatabase from '@expo/websql/custom';
3
3
  import { NativeModulesProxy } from 'expo-modules-core';
4
- import zipObject from 'lodash/zipObject';
5
4
  import { Platform } from 'react-native';
6
5
  const { ExponentSQLite } = NativeModulesProxy;
6
+ function zipObject(keys, values) {
7
+ const result = {};
8
+ for (let i = 0; i < keys.length; i++) {
9
+ result[keys[i]] = values[i];
10
+ }
11
+ return result;
12
+ }
7
13
  class SQLiteDatabase {
8
14
  _name;
9
15
  _closed = false;
@@ -23,7 +29,13 @@ class SQLiteDatabase {
23
29
  }
24
30
  close() {
25
31
  this._closed = true;
26
- 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);
27
39
  }
28
40
  }
29
41
  function _serializeQuery(query) {
@@ -56,16 +68,10 @@ function _escapeBlob(data) {
56
68
  }
57
69
  }
58
70
  const _openExpoSQLiteDatabase = customOpenDatabase(SQLiteDatabase);
59
- function addExecMethod(db) {
60
- db.exec = (queries, readOnly, callback) => {
61
- db._db.exec(queries, readOnly, callback);
62
- };
63
- return db;
64
- }
65
71
  // @needsAudit @docsMissing
66
72
  /**
67
73
  * Open a database, creating it if it doesn't exist, and return a `Database` object. On disk,
68
- * the database will be created under the app's [documents directory](../filesystem), i.e.
74
+ * the database will be created under the app's [documents directory](./filesystem), i.e.
69
75
  * `${FileSystem.documentDirectory}/SQLite/${name}`.
70
76
  * > The `version`, `description` and `size` arguments are ignored, but are accepted by the function
71
77
  * for compatibility with the WebSQL specification.
@@ -81,7 +87,9 @@ export function openDatabase(name, version = '1.0', description = name, size = 1
81
87
  throw new TypeError(`The database name must not be undefined`);
82
88
  }
83
89
  const db = _openExpoSQLiteDatabase(name, version, description, size, callback);
84
- const dbWithExec = addExecMethod(db);
85
- return dbWithExec;
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;
86
94
  }
87
95
  //# sourceMappingURL=SQLite.js.map
@@ -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,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAIxC,MAAM,EAAE,cAAc,EAAE,GAAG,kBAAkB,CAAC;AAE9C,MAAM,cAAc;IAClB,KAAK,CAAS;IACd,OAAO,GAAY,KAAK,CAAC;IAEzB,YAAY,IAAY;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,IAAI,CAAC,OAAgB,EAAE,QAAiB,EAAE,QAAwB;QAChE,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,+BAA+B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AE,GAAG,CAAC,CAAC;KACjD,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAI,IAAO;IAC7B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,qCAAqC;QACrC,OAAO,IAAI;aACR,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC;aAClC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC;aAClC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAQ,CAAC;QAC7C,oCAAoC;KACrC;SAAM;QACL,OAAO,IAAI,CAAC;KACb;AACH,CAAC;AAED,MAAM,uBAAuB,GAAG,kBAAkB,CAAC,cAAc,CAAC,CAAC;AAEnE,SAAS,aAAa,CAAC,EAAO;IAC5B,EAAE,CAAC,IAAI,GAAG,CAAC,OAAgB,EAAE,QAAiB,EAAE,QAAwB,EAAQ,EAAE;QAChF,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC3C,CAAC,CAAC;IACF,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,2BAA2B;AAC3B;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,UAAkB,KAAK,EACvB,cAAsB,IAAI,EAC1B,OAAe,CAAC,EAChB,QAAuC;IAEvC,IAAI,IAAI,KAAK,SAAS,EAAE;QACtB,MAAM,IAAI,SAAS,CAAC,yCAAyC,CAAC,CAAC;KAChE;IACD,MAAM,EAAE,GAAG,uBAAuB,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC/E,MAAM,UAAU,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IACrC,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import './polyfillNextTick';\n\nimport customOpenDatabase from '@expo/websql/custom';\nimport { NativeModulesProxy } from 'expo-modules-core';\nimport zipObject from 'lodash/zipObject';\nimport { Platform } from 'react-native';\n\nimport { Query, SQLiteCallback, ResultSet, ResultSetError, WebSQLDatabase } from './SQLite.types';\n\nconst { ExponentSQLite } = NativeModulesProxy;\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 ExponentSQLite.close(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\nfunction addExecMethod(db: any): WebSQLDatabase {\n db.exec = (queries: Query[], readOnly: boolean, callback: SQLiteCallback): void => {\n db._db.exec(queries, readOnly, callback);\n };\n return db;\n}\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 const dbWithExec = addExecMethod(db);\n return dbWithExec;\n}\n"]}
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;IAED,IAAI,CAAC,OAAgB,EAAE,QAAiB,EAAE,QAAwB;QAChE,IAAI,IAAI,CAAC,OAAO,EAAE;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1C,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"]}
@@ -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
+ //# s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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 strings) 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)[],\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// @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"]}
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 strings) 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)[],\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"]}
@@ -1,2 +1,3 @@
1
1
  import { DatabaseCallback } from './SQLite.types';
2
2
  export declare function openDatabase(name: string, version?: string, description?: string, size?: number, callback?: DatabaseCallback): import("./SQLite.types").Database;
3
+ //# sourceMappingURL=SQLite.web.d.ts.map
@@ -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
@@ -1,2 +1,3 @@
1
1
  export * from './SQLite';
2
2
  export * from './SQLite.types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -2,3 +2,4 @@
2
2
  * Defines a small polyfill for process.nextTick. Eventually we'd like to replace this polyfill with
3
3
  * a native implementation with the correct timing semantics.
4
4
  */
5
+ //# sourceMappingURL=polyfillNextTick.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polyfillNextTick.d.ts","sourceRoot":"","sources":["../src/polyfillNextTick.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -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.0.3",
3
+ "version": "10.2.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",
@@ -33,16 +33,16 @@
33
33
  "license": "MIT",
34
34
  "homepage": "https://docs.expo.dev/versions/latest/sdk/sqlite/",
35
35
  "jest": {
36
- "preset": "expo-module-scripts/ios"
36
+ "preset": "expo-module-scripts"
37
37
  },
38
38
  "dependencies": {
39
- "@expo/websql": "^1.0.1",
40
- "expo-modules-core": "~0.4.4",
41
- "lodash": "^4.17.15"
39
+ "@expo/websql": "^1.0.1"
42
40
  },
43
41
  "devDependencies": {
44
- "@types/lodash.zipobject": "^4.1.4",
45
42
  "expo-module-scripts": "^2.0.0"
46
43
  },
47
- "gitHead": "4fa0497a180ae707fa860cb03858630ab7af19f4"
44
+ "peerDependencies": {
45
+ "expo": "*"
46
+ },
47
+ "gitHead": "22dce752354bb429c84851bc4389abe47a766b1f"
48
48
  }
package/src/SQLite.ts CHANGED
@@ -2,13 +2,20 @@ import './polyfillNextTick';
2
2
 
3
3
  import customOpenDatabase from '@expo/websql/custom';
4
4
  import { NativeModulesProxy } from 'expo-modules-core';
5
- import zipObject from 'lodash/zipObject';
6
5
  import { Platform } from 'react-native';
7
6
 
8
- import { Query, SQLiteCallback, ResultSet, ResultSetError, WebSQLDatabase } from './SQLite.types';
7
+ import { Query, ResultSet, ResultSetError, SQLiteCallback, WebSQLDatabase } from './SQLite.types';
9
8
 
10
9
  const { ExponentSQLite } = NativeModulesProxy;
11
10
 
11
+ function zipObject(keys: string[], values: any[]) {
12
+ const result = {};
13
+ for (let i = 0; i < keys.length; i++) {
14
+ result[keys[i]] = values[i];
15
+ }
16
+ return result;
17
+ }
18
+
12
19
  class SQLiteDatabase {
13
20
  _name: string;
14
21
  _closed: boolean = false;
@@ -35,7 +42,17 @@ class SQLiteDatabase {
35
42
 
36
43
  close() {
37
44
  this._closed = true;
38
- 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);
39
56
  }
40
57
  }
41
58
 
@@ -73,17 +90,10 @@ function _escapeBlob<T>(data: T): T {
73
90
 
74
91
  const _openExpoSQLiteDatabase = customOpenDatabase(SQLiteDatabase);
75
92
 
76
- function addExecMethod(db: any): WebSQLDatabase {
77
- db.exec = (queries: Query[], readOnly: boolean, callback: SQLiteCallback): void => {
78
- db._db.exec(queries, readOnly, callback);
79
- };
80
- return db;
81
- }
82
-
83
93
  // @needsAudit @docsMissing
84
94
  /**
85
95
  * Open a database, creating it if it doesn't exist, and return a `Database` object. On disk,
86
- * the database will be created under the app's [documents directory](../filesystem), i.e.
96
+ * the database will be created under the app's [documents directory](./filesystem), i.e.
87
97
  * `${FileSystem.documentDirectory}/SQLite/${name}`.
88
98
  * > The `version`, `description` and `size` arguments are ignored, but are accepted by the function
89
99
  * for compatibility with the WebSQL specification.
@@ -105,6 +115,8 @@ export function openDatabase(
105
115
  throw new TypeError(`The database name must not be undefined`);
106
116
  }
107
117
  const db = _openExpoSQLiteDatabase(name, version, description, size, callback);
108
- const dbWithExec = addExecMethod(db);
109
- return dbWithExec;
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;
110
122
  }
@@ -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