Skip to content

Commit

Permalink
deps: Add expo-sqlite
Browse files Browse the repository at this point in the history
This isn't quite the latest version; for now we'll use v9.x in order
to stick with "unimodules".  Issue #5133 is open for the migration
that'll let us advance to v10.x.

Include a libdef, generated with flowgen with small manual fixups
as described in comments.  The libdef is actually from a newer
version because that's what I tried first; I tried rerunning flowgen
on the older version, and the differences in the new one are pure
compatible improvements (cleaning up some type definitions; adding
comments; replacing `any[]` as the type for `args` on `executeSql`.)
  • Loading branch information
gnprice committed Jan 11, 2022
1 parent 22c77ef commit 995422a
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public List<Package> getPackageList() {
new expo.modules.filesystem.FileSystemPackage(),
new expo.modules.imageloader.ImageLoaderPackage(),
new expo.modules.screenorientation.ScreenOrientationPackage(),
new expo.modules.sqlite.SQLitePackage(),
new expo.modules.webbrowser.WebBrowserPackage()
);
}
Expand Down
199 changes: 199 additions & 0 deletions flow-typed/expo-sqlite_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// `flowgen --no-inexact --interface-records node_modules/expo-sqlite/build/SQLite.types.d.ts`
// from expo-sqlite 10.0.3
// with s/export type/declare export type/g
declare module 'expo-sqlite/build/SQLite.types' {
/**
* Flowtype definitions for SQLite.types
* Generated by Flowgen from a Typescript Definition
* Flowgen v1.14.1
*/

declare export type Window = {|
openDatabase?: (
name: string,
version: string,
displayName: string,
estimatedSize: number,
creationCallback?: DatabaseCallback
) => Database,
|};
declare export 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.
*/
declare export type 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?: () => void
): void,
readTransaction(
callback: SQLTransactionCallback,
errorCallback?: SQLTransactionErrorCallback,
successCallback?: () => void
): void,
|};
declare export type SQLTransactionCallback = (transaction: SQLTransaction) => void;
declare export 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.
*/
declare export type 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?: (number | string)[],
callback?: SQLStatementCallback,
errorCallback?: SQLStatementErrorCallback
): void,
|};
declare export type SQLStatementCallback = (
transaction: SQLTransaction,
resultSet: SQLResultSet
) => void;
declare export type SQLStatementErrorCallback = (
transaction: SQLTransaction,
error: SQLError
) => boolean;
declare 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,
|};
declare export type 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[],
|};
declare export class SQLError {
static UNKNOWN_ERR: number;
static DATABASE_ERR: number;
static VERSION_ERR: number;
static TOO_LARGE_ERR: number;
static QUOTA_ERR: number;
static SYNTAX_ERR: number;
static CONSTRAINT_ERR: number;
static TIMEOUT_ERR: number;
code: number;
message: string;
}
declare export type WebSQLDatabase = {|
...$Exact<Database>,

exec(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void,
|};
declare export type Query = {|
sql: string,
args: mixed[],
|};
declare export type ResultSetError = {|
error: Error,
|};
/**
* `ResultSet` objects are returned through second parameter of the `success` callback for the
* `tx.executeSql()` method on a `SQLTransaction` (see above).
*/
declare 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,
|}[],
|};
declare export type SQLiteCallback = (
error?: Error | null,
resultSet?: (ResultSetError | ResultSet)[]
) => void;
}

// `flowgen --no-inexact --interface-records node_modules/expo-sqlite/build/SQLite.d.ts`
// from expo-sqlite 10.0.3
// with imports fixed up
declare module 'expo-sqlite/build/SQLite' {
/**
* Flowtype definitions for SQLite
* Generated by Flowgen from a Typescript Definition
* Flowgen v1.14.1
*/

import type { WebSQLDatabase } from "expo-sqlite/build/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
*/
declare export function openDatabase(
name: string,
version?: string,
description?: string,
size?: number,
callback?: (db: WebSQLDatabase) => void
): WebSQLDatabase;
}

declare module 'expo-sqlite' {
declare export * from 'expo-sqlite/build/SQLite';
declare export * from 'expo-sqlite/build/SQLite.types';
}
7 changes: 7 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ PODS:
- EXScreenOrientation (3.3.0):
- React-Core
- UMCore
- EXSQLite (9.2.1):
- ExpoModulesCore
- UMCore
- EXWebBrowser (9.2.0):
- UMCore
- FBLazyVector (0.64.3)
Expand Down Expand Up @@ -430,6 +433,7 @@ DEPENDENCIES:
- EXImageLoader (from `../node_modules/expo-image-loader/ios`)
- ExpoModulesCore (from `../node_modules/expo-modules-core/ios`)
- EXScreenOrientation (from `../node_modules/expo-screen-orientation/ios`)
- EXSQLite (from `../node_modules/expo-sqlite/ios`)
- EXWebBrowser (from `../node_modules/expo-web-browser/ios`)
- FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`)
- FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`)
Expand Down Expand Up @@ -534,6 +538,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/expo-modules-core/ios"
EXScreenOrientation:
:path: "../node_modules/expo-screen-orientation/ios"
EXSQLite:
:path: "../node_modules/expo-sqlite/ios"
EXWebBrowser:
:path: "../node_modules/expo-web-browser/ios"
FBLazyVector:
Expand Down Expand Up @@ -642,6 +648,7 @@ SPEC CHECKSUMS:
EXImageLoader: d3531a3fe530b22925c19977cb53bb43e3821fe6
ExpoModulesCore: 2734852616127a6c1fc23012197890a6f3763dc7
EXScreenOrientation: 09fe6b6b87899ae0c9320255bda7b7513cdfc8ec
EXSQLite: cddb3b3f4c6999761c157b88dc8b55c7af2cd86b
EXWebBrowser: 76783ba5dcb8699237746ecf41a9643d428a4cc5
FBLazyVector: c71c5917ec0ad2de41d5d06a5855f6d5eda06971
FBReactNativeSpec: ddd61666683147c613f5c89e2ce4e6c5e4f90d63
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const transformModulesWhitelist = [
'expo-apple-authentication',
'expo-application',
'expo-sqlite',
'expo-web-browser',
'react-native',
'@react-native',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"expo-apple-authentication": "^3.2.1",
"expo-application": "^3.2.0",
"expo-screen-orientation": "^3.3.0",
"expo-sqlite": "^9.1.0",
"expo-web-browser": "^9.1.0",
"immutable": "^4.0.0-rc.12",
"invariant": "^2.2.4",
Expand Down
45 changes: 45 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,17 @@
"@types/hoist-non-react-statics" "^3.3.1"
hoist-non-react-statics "^3.3.0"

"@expo/websql@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@expo/websql/-/websql-1.0.1.tgz#fff0cf9c1baa1f70f9e1d658b7c39a420d9b10a9"
integrity sha1-//DPnBuqH3D54dZYt8OaQg2bEKk=
dependencies:
argsarray "^0.0.1"
immediate "^3.2.2"
noop-fn "^1.0.0"
pouchdb-collections "^1.0.1"
tiny-queue "^0.2.1"

"@formatjs/ecma402-abstract@1.9.3":
version "1.9.3"
resolved "https://registry.yarnpkg.com/@formatjs/ecma402-abstract/-/ecma402-abstract-1.9.3.tgz#00892014c805935b5b1345d238246e9bf3a2de50"
Expand Down Expand Up @@ -2831,6 +2842,11 @@ argparse@^1.0.7, argparse@^1.0.9:
dependencies:
sprintf-js "~1.0.2"

argsarray@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/argsarray/-/argsarray-0.0.1.tgz#6e7207b4ecdb39b0af88303fa5ae22bda8df61cb"
integrity sha1-bnIHtOzbObCviDA/pa4ivajfYcs=

aria-query@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-4.2.2.tgz#0d2ca6c9aceb56b8977e9fed6aed7e15bbd2f83b"
Expand Down Expand Up @@ -4955,6 +4971,15 @@ expo-screen-orientation@^3.3.0:
dependencies:
"@expo/config-plugins" "^3.0.0"

expo-sqlite@^9.1.0:
version "9.2.1"
resolved "https://registry.yarnpkg.com/expo-sqlite/-/expo-sqlite-9.2.1.tgz#ec08f874f64d41278b6c27a4a63f8acd192c65c1"
integrity sha512-OTN3Dn/S07rmPEiMA8D4OXWvSwahckyAFWqgCAPUy6yjYI1O5ykhXZ37eerFJNMgSZqfOQ719lpYB0pdIKY6kA==
dependencies:
"@expo/websql" "^1.0.1"
expo-modules-core "~0.2.0"
lodash "^4.17.15"

expo-web-browser@^9.1.0:
version "9.2.0"
resolved "https://registry.yarnpkg.com/expo-web-browser/-/expo-web-browser-9.2.0.tgz#34c1355552c4c6eaae515340a0761939a9bf6152"
Expand Down Expand Up @@ -5787,6 +5812,11 @@ image-size@^0.6.0:
resolved "https://registry.yarnpkg.com/image-size/-/image-size-0.6.3.tgz#e7e5c65bb534bd7cdcedd6cb5166272a85f75fb2"
integrity sha512-47xSUiQioGaB96nqtp5/q55m0aBQSQdyIloMOc/x+QVTDZLNmXE892IIDrJ0hM1A5vcNUDD5tDffkSP5lCaIIA==

immediate@^3.2.2:
version "3.3.0"
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.3.0.tgz#1aef225517836bcdf7f2a2de2600c79ff0269266"
integrity sha512-HR7EVodfFUdQCTIeySw+WDRFJlPcLOJbXfwwZ7Oom6tjsvZ3bOkCDJHehQC3nxJrv7+f9XecwazynjU8e4Vw3Q==

immediate@~3.0.5:
version "3.0.6"
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
Expand Down Expand Up @@ -8137,6 +8167,11 @@ node-stream-zip@^1.9.1:
resolved "https://registry.yarnpkg.com/node-stream-zip/-/node-stream-zip-1.15.0.tgz#158adb88ed8004c6c49a396b50a6a5de3bca33ea"
integrity sha512-LN4fydt9TqhZhThkZIVQnF9cwjU3qmUH9h78Mx/K7d3VvfRqqwthLwJEUOEL0QPZ0XQmNN7be5Ggit5+4dq3Bw==

noop-fn@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/noop-fn/-/noop-fn-1.0.0.tgz#5f33d47f13d2150df93e0cb036699e982f78ffbf"
integrity sha1-XzPUfxPSFQ35PgywNmmemC94/78=

normalize-package-data@^2.3.2, normalize-package-data@^2.5.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8"
Expand Down Expand Up @@ -8682,6 +8717,11 @@ posix-character-classes@^0.1.0:
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=

pouchdb-collections@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/pouchdb-collections/-/pouchdb-collections-1.0.1.tgz#fe63a17da977611abef7cb8026cb1a9553fd8359"
integrity sha1-/mOhfal3YRq+98uAJssalVP9g1k=

prelude-ls@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
Expand Down Expand Up @@ -10366,6 +10406,11 @@ timezone@^1.0.13:
resolved "https://registry.yarnpkg.com/timezone/-/timezone-1.0.23.tgz#87865e2c9d6aff6a52a598247e8f5102a92c881b"
integrity sha512-yhQgk6qmSLB+TF8HGmApZAVI5bfzR1CoKUGr+WMZWmx75ED1uDewAZA8QMGCQ70TEv4GmM8pDB9jrHuxdaQ1PA==

tiny-queue@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/tiny-queue/-/tiny-queue-0.2.1.tgz#25a67f2c6e253b2ca941977b5ef7442ef97a6046"
integrity sha1-JaZ/LG4lOyypQZd7XvdELvl6YEY=

tmp@^0.0.33:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
Expand Down

0 comments on commit 995422a

Please sign in to comment.