@op-engineering/op-sqlite 2.0.1 → 2.0.3
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/README.md +57 -17
- package/android/CMakeLists.txt +4 -2
- package/cpp/DumbHostObject.cpp +32 -27
- package/cpp/DumbHostObject.h +16 -16
- package/cpp/PreparedStatementHostObject.cpp +88 -0
- package/cpp/PreparedStatementHostObject.h +36 -0
- package/cpp/SmartHostObject.cpp +33 -0
- package/cpp/SmartHostObject.h +26 -0
- package/cpp/ThreadPool.cpp +103 -116
- package/cpp/ThreadPool.h +27 -27
- package/cpp/bindings.cpp +525 -530
- package/cpp/bindings.h +6 -5
- package/cpp/bridge.cpp +713 -651
- package/cpp/bridge.h +41 -19
- package/cpp/logs.h +17 -17
- package/cpp/macros.h +1 -1
- package/cpp/sqlbatchexecutor.cpp +75 -77
- package/cpp/sqlbatchexecutor.h +9 -8
- package/cpp/sqlite3.h +1295 -1389
- package/cpp/types.h +5 -4
- package/cpp/utils.cpp +159 -191
- package/cpp/utils.h +28 -35
- package/lib/commonjs/index.js +2 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +6 -0
- package/op-sqlite.podspec +1 -1
- package/package.json +2 -1
- package/src/index.ts +8 -0
- package/cpp/DynamicHostObject.cpp +0 -32
- package/cpp/DynamicHostObject.h +0 -26
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","global","__OPSQLiteProxy","OPSQLiteModule","OPSQLite","Error","nativeCallSyncHook","install","result","proxy","IOS_DOCUMENT_PATH","IOS_LIBRARY_PATH","ANDROID_DATABASE_PATH","ANDROID_FILES_PATH","ANDROID_EXTERNAL_FILES_PATH","locks","enhanceQueryResult","rows","_array","length","item","idx","_open","open","dbName","location","queue","inProgress","_close","close","_execute","execute","query","params","sanitizedParams","map","p","ArrayBuffer","isView","buffer","_executeAsync","executeAsync","res","transaction","fn","isFinalized","commit","rollback","run","executionError","rollbackError","startNextTransaction","Promise","resolve","reject","tx","start","then","catch","push","shift","setImmediate","options","name","delete","attach","dbNameToAttach","alias","detach","executeBatch","commands","executeBatchAsync","loadFile","updateHook","callback","commitHook","rollbackHook"],"sources":["index.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\ndeclare global {\n function nativeCallSyncHook(): unknown;\n var __OPSQLiteProxy: object | undefined;\n}\n\nif (global.__OPSQLiteProxy == null) {\n const OPSQLiteModule = NativeModules.OPSQLite;\n\n if (OPSQLiteModule == null) {\n throw new Error('Base module not found. Maybe try rebuilding the app.');\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || OPSQLiteModule.install == null) {\n throw new Error(\n 'Failed to install op-sqlite: React Native is not running on-device. OPSQLite can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = OPSQLiteModule.install();\n if (result !== true) {\n throw new Error(\n `Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n }\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.__OPSQLiteProxy == null) {\n throw new Error(\n 'Failed to install op-sqlite, the native initializer function does not exist. Are you trying to use OPSQLite from different JS Runtimes?'\n );\n }\n}\n\nconst proxy = global.__OPSQLiteProxy;\nexport const OPSQLite = proxy as ISQLite;\n\nexport const {\n IOS_DOCUMENT_PATH,\n IOS_LIBRARY_PATH,\n ANDROID_DATABASE_PATH,\n ANDROID_FILES_PATH,\n ANDROID_EXTERNAL_FILES_PATH,\n} = NativeModules.OPSQLite;\n\n/**\n * Object returned by SQL Query executions {\n * insertId: Represent the auto-generated row id if applicable\n * rowsAffected: Number of affected rows if result of a update query\n * message: if status === 1, here you will find error description\n * rows: if status is undefined or 0 this object will contain the query results\n * }\n *\n * @interface QueryResult\n */\nexport type QueryResult = {\n insertId?: number;\n rowsAffected: number;\n rows?: {\n /** Raw array with all dataset */\n _array: any[];\n /** The lengh of the dataset */\n length: number;\n /** A convenience function to acess the index based the row object\n * @param idx the row index\n * @returns the row structure identified by column names\n */\n item: (idx: number) => any;\n };\n /**\n * Query metadata, avaliable only for select query results\n */\n metadata?: ColumnMetadata[];\n};\n\n/**\n * Column metadata\n * Describes some information about columns fetched by the query\n */\nexport type ColumnMetadata = {\n /** The name used for this column for this resultset */\n name: string;\n /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. \"UNKNOWN\" for dynamic values, like function returned ones. */\n type: string;\n /**\n * The index for this column for this resultset*/\n index: number;\n};\n\n/**\n * Allows the execution of bulk of sql commands\n * inside a transaction\n * If a single query must be executed many times with different arguments, its preferred\n * to declare it a single time, and use an array of array parameters.\n */\nexport type SQLBatchTuple = [string] | [string, Array<any> | Array<Array<any>>];\n\nexport type UpdateHookOperation = 'INSERT' | 'DELETE' | 'UPDATE';\n\n/**\n * status: 0 or undefined for correct execution, 1 for error\n * message: if status === 1, here you will find error description\n * rowsAffected: Number of affected rows if status == 0\n */\nexport type BatchQueryResult = {\n rowsAffected?: number;\n};\n\n/**\n * Result of loading a file and executing every line as a SQL command\n * Similar to BatchQueryResult\n */\nexport interface FileLoadResult extends BatchQueryResult {\n commands?: number;\n}\n\nexport interface Transaction {\n commit: () => QueryResult;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ) => Promise<QueryResult>;\n rollback: () => QueryResult;\n}\n\nexport interface PendingTransaction {\n /*\n * The start function should not throw or return a promise because the\n * queue just calls it and does not monitor for failures or completions.\n *\n * It should catch any errors and call the resolve or reject of the wrapping\n * promise when complete.\n *\n * It should also automatically commit or rollback the transaction if needed\n */\n start: () => void;\n}\n\ninterface ISQLite {\n open: (dbName: string, location?: string) => void;\n close: (dbName: string) => void;\n delete: (dbName: string, location?: string) => void;\n attach: (\n mainDbName: string,\n dbNameToAttach: string,\n alias: string,\n location?: string\n ) => void;\n detach: (mainDbName: string, alias: string) => void;\n transaction: (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n ) => Promise<void>;\n execute: (dbName: string, query: string, params?: any[]) => QueryResult;\n executeAsync: (\n dbName: string,\n query: string,\n params?: any[]\n ) => Promise<QueryResult>;\n executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (\n dbName: string,\n commands: SQLBatchTuple[]\n ) => Promise<BatchQueryResult>;\n loadFile: (dbName: string, location: string) => Promise<FileLoadResult>;\n updateHook: (\n dbName: string,\n callback?:\n | ((params: {\n table: string;\n operation: UpdateHookOperation;\n row?: any;\n rowId: number;\n }) => void)\n | null\n ) => void;\n commitHook: (dbName: string, callback?: (() => void) | null) => void;\n rollbackHook: (dbName: string, callback?: (() => void) | null) => void;\n}\n\nconst locks: Record<\n string,\n { queue: PendingTransaction[]; inProgress: boolean }\n> = {};\n\n// Enhance some host functions\n\n// Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\nfunction enhanceQueryResult(result: QueryResult): void {\n // Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\n if (result.rows == null) {\n result.rows = {\n _array: [],\n length: 0,\n item: (idx: number) => result.rows?._array[idx],\n };\n } else {\n result.rows.item = (idx: number) => result.rows?._array[idx];\n }\n}\n\nconst _open = OPSQLite.open;\nOPSQLite.open = (dbName: string, location?: string) => {\n _open(dbName, location);\n\n locks[dbName] = {\n queue: [],\n inProgress: false,\n };\n};\n\nconst _close = OPSQLite.close;\nOPSQLite.close = (dbName: string) => {\n _close(dbName);\n delete locks[dbName];\n};\n\nconst _execute = OPSQLite.execute;\nOPSQLite.execute = (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): QueryResult => {\n const sanitizedParams = params?.map((p) => {\n if (ArrayBuffer.isView(p)) {\n return p.buffer;\n }\n\n return p;\n });\n\n const result = _execute(dbName, query, sanitizedParams);\n enhanceQueryResult(result);\n return result;\n};\n\nconst _executeAsync = OPSQLite.executeAsync;\nOPSQLite.executeAsync = async (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): Promise<QueryResult> => {\n const sanitizedParams = params?.map((p) => {\n if (ArrayBuffer.isView(p)) {\n return p.buffer;\n }\n\n return p;\n });\n\n const res = await _executeAsync(dbName, query, sanitizedParams);\n enhanceQueryResult(res);\n return res;\n};\n\nOPSQLite.transaction = async (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n): Promise<void> => {\n if (!locks[dbName]) {\n throw Error(`SQLite Error: No lock found on db: ${dbName}`);\n }\n\n let isFinalized = false;\n\n // Local transaction context object implementation\n const execute = (query: string, params?: any[]): QueryResult => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.execute(dbName, query, params);\n };\n\n const executeAsync = (query: string, params?: any[] | undefined) => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.executeAsync(dbName, query, params);\n };\n\n const commit = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute commit on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'COMMIT');\n isFinalized = true;\n return result;\n };\n\n const rollback = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute rollback on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'ROLLBACK');\n isFinalized = true;\n return result;\n };\n\n async function run() {\n try {\n await OPSQLite.executeAsync(dbName, 'BEGIN TRANSACTION');\n\n await fn({\n commit,\n execute,\n executeAsync,\n rollback,\n });\n\n if (!isFinalized) {\n commit();\n }\n } catch (executionError) {\n if (!isFinalized) {\n try {\n rollback();\n } catch (rollbackError) {\n throw rollbackError;\n }\n }\n\n throw executionError;\n } finally {\n locks[dbName].inProgress = false;\n isFinalized = false;\n startNextTransaction(dbName);\n }\n }\n\n return await new Promise((resolve, reject) => {\n const tx: PendingTransaction = {\n start: () => {\n run().then(resolve).catch(reject);\n },\n };\n\n locks[dbName].queue.push(tx);\n startNextTransaction(dbName);\n });\n};\n\nconst startNextTransaction = (dbName: string) => {\n if (!locks[dbName]) {\n throw Error(`Lock not found for db: ${dbName}`);\n }\n\n if (locks[dbName].inProgress) {\n // Transaction is already in process bail out\n return;\n }\n\n if (locks[dbName].queue.length) {\n locks[dbName].inProgress = true;\n const tx = locks[dbName].queue.shift();\n\n if (!tx) {\n throw new Error('Could not get a operation on datebase');\n }\n\n setImmediate(() => {\n tx.start();\n });\n }\n};\n\nexport type OPSQLiteConnection = {\n close: () => void;\n delete: () => void;\n attach: (dbNameToAttach: string, alias: string, location?: string) => void;\n detach: (alias: string) => void;\n transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (query: string, params?: any[]) => Promise<QueryResult>;\n executeBatch: (commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;\n loadFile: (location: string) => Promise<FileLoadResult>;\n updateHook: (\n callback:\n | ((params: {\n table: string;\n operation: UpdateHookOperation;\n row?: any;\n rowId: number;\n }) => void)\n | null\n ) => void;\n commitHook: (callback: (() => void) | null) => void;\n rollbackHook: (callback: (() => void) | null) => void;\n};\n\nexport const open = (options: {\n name: string;\n location?: string;\n}): OPSQLiteConnection => {\n OPSQLite.open(options.name, options.location);\n\n return {\n close: () => OPSQLite.close(options.name),\n delete: () => OPSQLite.delete(options.name, options.location),\n attach: (dbNameToAttach: string, alias: string, location?: string) =>\n OPSQLite.attach(options.name, dbNameToAttach, alias, location),\n detach: (alias: string) => OPSQLite.detach(options.name, alias),\n transaction: (fn: (tx: Transaction) => Promise<void>) =>\n OPSQLite.transaction(options.name, fn),\n execute: (query: string, params?: any[] | undefined): QueryResult =>\n OPSQLite.execute(options.name, query, params),\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ): Promise<QueryResult> =>\n OPSQLite.executeAsync(options.name, query, params),\n executeBatch: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatch(options.name, commands),\n executeBatchAsync: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatchAsync(options.name, commands),\n loadFile: (location: string) => OPSQLite.loadFile(options.name, location),\n updateHook: (callback) => OPSQLite.updateHook(options.name, callback),\n commitHook: (callback) => OPSQLite.commitHook(options.name, callback),\n rollbackHook: (callback) => OPSQLite.rollbackHook(options.name, callback),\n };\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAO5C,IAAIC,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;EAClC,MAAMC,cAAc,GAAGH,aAAa,CAACI,QAAQ;EAE7C,IAAID,cAAc,IAAI,IAAI,EAAE;IAC1B,MAAM,IAAIE,KAAK,CAAC,sDAAsD,CAAC;EACzE;;EAEA;EACA,IAAIJ,MAAM,CAACK,kBAAkB,IAAI,IAAI,IAAIH,cAAc,CAACI,OAAO,IAAI,IAAI,EAAE;IACvE,MAAM,IAAIF,KAAK,CACb,iQAAiQ,CAClQ;EACH;;EAEA;EACA,MAAMG,MAAM,GAAGL,cAAc,CAACI,OAAO,EAAE;EACvC,IAAIC,MAAM,KAAK,IAAI,EAAE;IACnB,MAAM,IAAIH,KAAK,CACZ,iJAAgJG,MAAO,EAAC,CAC1J;EACH;;EAEA;EACA,IAAIP,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;IAClC,MAAM,IAAIG,KAAK,CACb,yIAAyI,CAC1I;EACH;AACF;AAEA,MAAMI,KAAK,GAAGR,MAAM,CAACC,eAAe;AACpC,OAAO,MAAME,QAAQ,GAAGK,KAAgB;AAExC,OAAO,MAAM;EACXC,iBAAiB;EACjBC,gBAAgB;EAChBC,qBAAqB;EACrBC,kBAAkB;EAClBC;AACF,CAAC,GAAGd,aAAa,CAACI,QAAQ;;AAE1B;AACA;AACA;AACA;A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KtE,QAAQ,CAACuE,UAAU,CAACb,OAAO,CAACC,IAAI,EAAEW,QAAQ,CAAC;IACrEE,YAAY,EAAGF,QAAQ,IAAKtE,QAAQ,CAACwE,YAAY,CAACd,OAAO,CAACC,IAAI,EAAEW,QAAQ;EAC1E,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"names":["NativeModules","global","__OPSQLiteProxy","OPSQLiteModule","OPSQLite","Error","nativeCallSyncHook","install","result","proxy","IOS_DOCUMENT_PATH","IOS_LIBRARY_PATH","ANDROID_DATABASE_PATH","ANDROID_FILES_PATH","ANDROID_EXTERNAL_FILES_PATH","locks","enhanceQueryResult","rows","_array","length","item","idx","_open","open","dbName","location","queue","inProgress","_close","close","_execute","execute","query","params","sanitizedParams","map","p","ArrayBuffer","isView","buffer","_executeAsync","executeAsync","res","transaction","fn","isFinalized","commit","rollback","run","executionError","rollbackError","startNextTransaction","Promise","resolve","reject","tx","start","then","catch","push","shift","setImmediate","options","name","delete","attach","dbNameToAttach","alias","detach","executeBatch","commands","executeBatchAsync","loadFile","updateHook","callback","commitHook","rollbackHook","prepareStatement"],"sources":["index.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\ndeclare global {\n function nativeCallSyncHook(): unknown;\n var __OPSQLiteProxy: object | undefined;\n}\n\nif (global.__OPSQLiteProxy == null) {\n const OPSQLiteModule = NativeModules.OPSQLite;\n\n if (OPSQLiteModule == null) {\n throw new Error('Base module not found. Maybe try rebuilding the app.');\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || OPSQLiteModule.install == null) {\n throw new Error(\n 'Failed to install op-sqlite: React Native is not running on-device. OPSQLite can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = OPSQLiteModule.install();\n if (result !== true) {\n throw new Error(\n `Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n }\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.__OPSQLiteProxy == null) {\n throw new Error(\n 'Failed to install op-sqlite, the native initializer function does not exist. Are you trying to use OPSQLite from different JS Runtimes?'\n );\n }\n}\n\nconst proxy = global.__OPSQLiteProxy;\nexport const OPSQLite = proxy as ISQLite;\n\nexport const {\n IOS_DOCUMENT_PATH,\n IOS_LIBRARY_PATH,\n ANDROID_DATABASE_PATH,\n ANDROID_FILES_PATH,\n ANDROID_EXTERNAL_FILES_PATH,\n} = NativeModules.OPSQLite;\n\n/**\n * Object returned by SQL Query executions {\n * insertId: Represent the auto-generated row id if applicable\n * rowsAffected: Number of affected rows if result of a update query\n * message: if status === 1, here you will find error description\n * rows: if status is undefined or 0 this object will contain the query results\n * }\n *\n * @interface QueryResult\n */\nexport type QueryResult = {\n insertId?: number;\n rowsAffected: number;\n rows?: {\n /** Raw array with all dataset */\n _array: any[];\n /** The lengh of the dataset */\n length: number;\n /** A convenience function to acess the index based the row object\n * @param idx the row index\n * @returns the row structure identified by column names\n */\n item: (idx: number) => any;\n };\n /**\n * Query metadata, avaliable only for select query results\n */\n metadata?: ColumnMetadata[];\n};\n\n/**\n * Column metadata\n * Describes some information about columns fetched by the query\n */\nexport type ColumnMetadata = {\n /** The name used for this column for this resultset */\n name: string;\n /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. \"UNKNOWN\" for dynamic values, like function returned ones. */\n type: string;\n /**\n * The index for this column for this resultset*/\n index: number;\n};\n\n/**\n * Allows the execution of bulk of sql commands\n * inside a transaction\n * If a single query must be executed many times with different arguments, its preferred\n * to declare it a single time, and use an array of array parameters.\n */\nexport type SQLBatchTuple = [string] | [string, Array<any> | Array<Array<any>>];\n\nexport type UpdateHookOperation = 'INSERT' | 'DELETE' | 'UPDATE';\n\n/**\n * status: 0 or undefined for correct execution, 1 for error\n * message: if status === 1, here you will find error description\n * rowsAffected: Number of affected rows if status == 0\n */\nexport type BatchQueryResult = {\n rowsAffected?: number;\n};\n\n/**\n * Result of loading a file and executing every line as a SQL command\n * Similar to BatchQueryResult\n */\nexport interface FileLoadResult extends BatchQueryResult {\n commands?: number;\n}\n\nexport interface Transaction {\n commit: () => QueryResult;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ) => Promise<QueryResult>;\n rollback: () => QueryResult;\n}\n\nexport interface PendingTransaction {\n /*\n * The start function should not throw or return a promise because the\n * queue just calls it and does not monitor for failures or completions.\n *\n * It should catch any errors and call the resolve or reject of the wrapping\n * promise when complete.\n *\n * It should also automatically commit or rollback the transaction if needed\n */\n start: () => void;\n}\n\nexport type PreparedStatementObj = {\n bind: (params: any[]) => void;\n execute: () => QueryResult;\n};\n\ninterface ISQLite {\n open: (dbName: string, location?: string) => void;\n close: (dbName: string) => void;\n delete: (dbName: string, location?: string) => void;\n attach: (\n mainDbName: string,\n dbNameToAttach: string,\n alias: string,\n location?: string\n ) => void;\n detach: (mainDbName: string, alias: string) => void;\n transaction: (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n ) => Promise<void>;\n execute: (dbName: string, query: string, params?: any[]) => QueryResult;\n executeAsync: (\n dbName: string,\n query: string,\n params?: any[]\n ) => Promise<QueryResult>;\n executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (\n dbName: string,\n commands: SQLBatchTuple[]\n ) => Promise<BatchQueryResult>;\n loadFile: (dbName: string, location: string) => Promise<FileLoadResult>;\n updateHook: (\n dbName: string,\n callback?:\n | ((params: {\n table: string;\n operation: UpdateHookOperation;\n row?: any;\n rowId: number;\n }) => void)\n | null\n ) => void;\n commitHook: (dbName: string, callback?: (() => void) | null) => void;\n rollbackHook: (dbName: string, callback?: (() => void) | null) => void;\n prepareStatement: (dbName: string, query: string) => PreparedStatementObj;\n}\n\nconst locks: Record<\n string,\n { queue: PendingTransaction[]; inProgress: boolean }\n> = {};\n\n// Enhance some host functions\n\n// Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\nfunction enhanceQueryResult(result: QueryResult): void {\n // Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\n if (result.rows == null) {\n result.rows = {\n _array: [],\n length: 0,\n item: (idx: number) => result.rows?._array[idx],\n };\n } else {\n result.rows.item = (idx: number) => result.rows?._array[idx];\n }\n}\n\nconst _open = OPSQLite.open;\nOPSQLite.open = (dbName: string, location?: string) => {\n _open(dbName, location);\n\n locks[dbName] = {\n queue: [],\n inProgress: false,\n };\n};\n\nconst _close = OPSQLite.close;\nOPSQLite.close = (dbName: string) => {\n _close(dbName);\n delete locks[dbName];\n};\n\nconst _execute = OPSQLite.execute;\nOPSQLite.execute = (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): QueryResult => {\n const sanitizedParams = params?.map((p) => {\n if (ArrayBuffer.isView(p)) {\n return p.buffer;\n }\n\n return p;\n });\n\n const result = _execute(dbName, query, sanitizedParams);\n enhanceQueryResult(result);\n return result;\n};\n\nconst _executeAsync = OPSQLite.executeAsync;\nOPSQLite.executeAsync = async (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): Promise<QueryResult> => {\n const sanitizedParams = params?.map((p) => {\n if (ArrayBuffer.isView(p)) {\n return p.buffer;\n }\n\n return p;\n });\n\n const res = await _executeAsync(dbName, query, sanitizedParams);\n enhanceQueryResult(res);\n return res;\n};\n\nOPSQLite.transaction = async (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n): Promise<void> => {\n if (!locks[dbName]) {\n throw Error(`SQLite Error: No lock found on db: ${dbName}`);\n }\n\n let isFinalized = false;\n\n // Local transaction context object implementation\n const execute = (query: string, params?: any[]): QueryResult => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.execute(dbName, query, params);\n };\n\n const executeAsync = (query: string, params?: any[] | undefined) => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.executeAsync(dbName, query, params);\n };\n\n const commit = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute commit on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'COMMIT');\n isFinalized = true;\n return result;\n };\n\n const rollback = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute rollback on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'ROLLBACK');\n isFinalized = true;\n return result;\n };\n\n async function run() {\n try {\n await OPSQLite.executeAsync(dbName, 'BEGIN TRANSACTION');\n\n await fn({\n commit,\n execute,\n executeAsync,\n rollback,\n });\n\n if (!isFinalized) {\n commit();\n }\n } catch (executionError) {\n if (!isFinalized) {\n try {\n rollback();\n } catch (rollbackError) {\n throw rollbackError;\n }\n }\n\n throw executionError;\n } finally {\n locks[dbName].inProgress = false;\n isFinalized = false;\n startNextTransaction(dbName);\n }\n }\n\n return await new Promise((resolve, reject) => {\n const tx: PendingTransaction = {\n start: () => {\n run().then(resolve).catch(reject);\n },\n };\n\n locks[dbName].queue.push(tx);\n startNextTransaction(dbName);\n });\n};\n\nconst startNextTransaction = (dbName: string) => {\n if (!locks[dbName]) {\n throw Error(`Lock not found for db: ${dbName}`);\n }\n\n if (locks[dbName].inProgress) {\n // Transaction is already in process bail out\n return;\n }\n\n if (locks[dbName].queue.length) {\n locks[dbName].inProgress = true;\n const tx = locks[dbName].queue.shift();\n\n if (!tx) {\n throw new Error('Could not get a operation on datebase');\n }\n\n setImmediate(() => {\n tx.start();\n });\n }\n};\n\nexport type OPSQLiteConnection = {\n close: () => void;\n delete: () => void;\n attach: (dbNameToAttach: string, alias: string, location?: string) => void;\n detach: (alias: string) => void;\n transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (query: string, params?: any[]) => Promise<QueryResult>;\n executeBatch: (commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;\n loadFile: (location: string) => Promise<FileLoadResult>;\n updateHook: (\n callback:\n | ((params: {\n table: string;\n operation: UpdateHookOperation;\n row?: any;\n rowId: number;\n }) => void)\n | null\n ) => void;\n commitHook: (callback: (() => void) | null) => void;\n rollbackHook: (callback: (() => void) | null) => void;\n prepareStatement: (query: string) => PreparedStatementObj;\n};\n\nexport const open = (options: {\n name: string;\n location?: string;\n}): OPSQLiteConnection => {\n OPSQLite.open(options.name, options.location);\n\n return {\n close: () => OPSQLite.close(options.name),\n delete: () => OPSQLite.delete(options.name, options.location),\n attach: (dbNameToAttach: string, alias: string, location?: string) =>\n OPSQLite.attach(options.name, dbNameToAttach, alias, location),\n detach: (alias: string) => OPSQLite.detach(options.name, alias),\n transaction: (fn: (tx: Transaction) => Promise<void>) =>\n OPSQLite.transaction(options.name, fn),\n execute: (query: string, params?: any[] | undefined): QueryResult =>\n OPSQLite.execute(options.name, query, params),\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ): Promise<QueryResult> =>\n OPSQLite.executeAsync(options.name, query, params),\n executeBatch: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatch(options.name, commands),\n executeBatchAsync: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatchAsync(options.name, commands),\n loadFile: (location: string) => OPSQLite.loadFile(options.name, location),\n updateHook: (callback) => OPSQLite.updateHook(options.name, callback),\n commitHook: (callback) => OPSQLite.commitHook(options.name, callback),\n rollbackHook: (callback) => OPSQLite.rollbackHook(options.name, callback),\n prepareStatement: (query) => OPSQLite.prepareStatement(options.name, query),\n };\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAO5C,IAAIC,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;EAClC,MAAMC,cAAc,GAAGH,aAAa,CAACI,QAAQ;EAE7C,IAAID,cAAc,IAAI,IAAI,EAAE;IAC1B,MAAM,IAAIE,KAAK,CAAC,sDAAsD,CAAC;E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2B,OAAO,CAAC+B,OAAO,CAACC,IAAI,EAAE/B,KAAK,EAAEC,MAAM,CAAC;IAC/CQ,YAAY,EAAE,CACZT,KAAa,EACbC,MAA0B,KAE1B7B,QAAQ,CAACqC,YAAY,CAACqB,OAAO,CAACC,IAAI,EAAE/B,KAAK,EAAEC,MAAM,CAAC;IACpDoC,YAAY,EAAGC,QAAyB,IACtClE,QAAQ,CAACiE,YAAY,CAACP,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IAC/CC,iBAAiB,EAAGD,QAAyB,IAC3ClE,QAAQ,CAACmE,iBAAiB,CAACT,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IACpDE,QAAQ,EAAG/C,QAAgB,IAAKrB,QAAQ,CAACoE,QAAQ,CAACV,OAAO,CAACC,IAAI,EAAEtC,QAAQ,CAAC;IACzEgD,UAAU,EAAGC,QAAQ,IAAKtE,QAAQ,CAACqE,UAAU,CAACX,OAAO,CAACC,IAAI,EAAEW,QAAQ,CAAC;IACrEC,UAAU,EAAGD,QAAQ,IAAKtE,QAAQ,CAACuE,UAAU,CAACb,OAAO,CAACC,IAAI,EAAEW,QAAQ,CAAC;IACrEE,YAAY,EAAGF,QAAQ,IAAKtE,QAAQ,CAACwE,YAAY,CAACd,OAAO,CAACC,IAAI,EAAEW,QAAQ,CAAC;IACzEG,gBAAgB,EAAG7C,KAAK,IAAK5B,QAAQ,CAACyE,gBAAgB,CAACf,OAAO,CAACC,IAAI,EAAE/B,KAAK;EAC5E,CAAC;AACH,CAAC"}
|
|
@@ -78,6 +78,10 @@ export interface Transaction {
|
|
|
78
78
|
export interface PendingTransaction {
|
|
79
79
|
start: () => void;
|
|
80
80
|
}
|
|
81
|
+
export type PreparedStatementObj = {
|
|
82
|
+
bind: (params: any[]) => void;
|
|
83
|
+
execute: () => QueryResult;
|
|
84
|
+
};
|
|
81
85
|
interface ISQLite {
|
|
82
86
|
open: (dbName: string, location?: string) => void;
|
|
83
87
|
close: (dbName: string) => void;
|
|
@@ -98,6 +102,7 @@ interface ISQLite {
|
|
|
98
102
|
}) => void) | null) => void;
|
|
99
103
|
commitHook: (dbName: string, callback?: (() => void) | null) => void;
|
|
100
104
|
rollbackHook: (dbName: string, callback?: (() => void) | null) => void;
|
|
105
|
+
prepareStatement: (dbName: string, query: string) => PreparedStatementObj;
|
|
101
106
|
}
|
|
102
107
|
export type OPSQLiteConnection = {
|
|
103
108
|
close: () => void;
|
|
@@ -118,6 +123,7 @@ export type OPSQLiteConnection = {
|
|
|
118
123
|
}) => void) | null) => void;
|
|
119
124
|
commitHook: (callback: (() => void) | null) => void;
|
|
120
125
|
rollbackHook: (callback: (() => void) | null) => void;
|
|
126
|
+
prepareStatement: (query: string) => PreparedStatementObj;
|
|
121
127
|
};
|
|
122
128
|
export declare const open: (options: {
|
|
123
129
|
name: string;
|
package/op-sqlite.podspec
CHANGED
|
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
|
|
|
11
11
|
s.license = package["license"]
|
|
12
12
|
s.authors = package["author"]
|
|
13
13
|
|
|
14
|
-
s.platforms = { :ios => "12.0", :osx => "10.
|
|
14
|
+
s.platforms = { :ios => "12.0", :osx => "10.13" }
|
|
15
15
|
s.source = { :git => "https://github.com/op-engineering/op-sqlite.git", :tag => "#{s.version}" }
|
|
16
16
|
|
|
17
17
|
s.pod_target_xcconfig = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@op-engineering/op-sqlite",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "Next generation SQLite for React Native",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"registry": "https://registry.npmjs.org/"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
+
"lefthook": "^1.5.5",
|
|
49
50
|
"react": "18.2.0",
|
|
50
51
|
"react-native": "0.72.6",
|
|
51
52
|
"react-native-builder-bob": "^0.18.2",
|
package/src/index.ts
CHANGED
|
@@ -140,6 +140,11 @@ export interface PendingTransaction {
|
|
|
140
140
|
start: () => void;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
export type PreparedStatementObj = {
|
|
144
|
+
bind: (params: any[]) => void;
|
|
145
|
+
execute: () => QueryResult;
|
|
146
|
+
};
|
|
147
|
+
|
|
143
148
|
interface ISQLite {
|
|
144
149
|
open: (dbName: string, location?: string) => void;
|
|
145
150
|
close: (dbName: string) => void;
|
|
@@ -180,6 +185,7 @@ interface ISQLite {
|
|
|
180
185
|
) => void;
|
|
181
186
|
commitHook: (dbName: string, callback?: (() => void) | null) => void;
|
|
182
187
|
rollbackHook: (dbName: string, callback?: (() => void) | null) => void;
|
|
188
|
+
prepareStatement: (dbName: string, query: string) => PreparedStatementObj;
|
|
183
189
|
}
|
|
184
190
|
|
|
185
191
|
const locks: Record<
|
|
@@ -398,6 +404,7 @@ export type OPSQLiteConnection = {
|
|
|
398
404
|
) => void;
|
|
399
405
|
commitHook: (callback: (() => void) | null) => void;
|
|
400
406
|
rollbackHook: (callback: (() => void) | null) => void;
|
|
407
|
+
prepareStatement: (query: string) => PreparedStatementObj;
|
|
401
408
|
};
|
|
402
409
|
|
|
403
410
|
export const open = (options: {
|
|
@@ -429,5 +436,6 @@ export const open = (options: {
|
|
|
429
436
|
updateHook: (callback) => OPSQLite.updateHook(options.name, callback),
|
|
430
437
|
commitHook: (callback) => OPSQLite.commitHook(options.name, callback),
|
|
431
438
|
rollbackHook: (callback) => OPSQLite.rollbackHook(options.name, callback),
|
|
439
|
+
prepareStatement: (query) => OPSQLite.prepareStatement(options.name, query),
|
|
432
440
|
};
|
|
433
441
|
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
#include "DynamicHostObject.h"
|
|
2
|
-
#include "utils.h"
|
|
3
|
-
#include <iostream>
|
|
4
|
-
|
|
5
|
-
namespace opsqlite {
|
|
6
|
-
|
|
7
|
-
namespace jsi = facebook::jsi;
|
|
8
|
-
|
|
9
|
-
std::vector<jsi::PropNameID> DynamicHostObject::getPropertyNames(jsi::Runtime &rt) {
|
|
10
|
-
std::vector<jsi::PropNameID> keys;
|
|
11
|
-
|
|
12
|
-
for (auto field : fields) {
|
|
13
|
-
keys.push_back(jsi::PropNameID::forAscii(rt, field.first));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return keys;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
jsi::Value DynamicHostObject::get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) {
|
|
20
|
-
auto name = propNameID.utf8(rt);
|
|
21
|
-
|
|
22
|
-
for (auto field: fields) {
|
|
23
|
-
auto fieldName = field.first;
|
|
24
|
-
if(fieldName == name) {
|
|
25
|
-
return toJSI(rt, field.second);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return {};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
package/cpp/DynamicHostObject.h
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
#ifndef DynamicHostObject_h
|
|
2
|
-
#define DynamicHostObject_h
|
|
3
|
-
|
|
4
|
-
#include <jsi/jsi.h>
|
|
5
|
-
#include <any>
|
|
6
|
-
#include <vector>
|
|
7
|
-
#include "types.h"
|
|
8
|
-
|
|
9
|
-
namespace opsqlite {
|
|
10
|
-
|
|
11
|
-
namespace jsi = facebook::jsi;
|
|
12
|
-
|
|
13
|
-
class JSI_EXPORT DynamicHostObject: public jsi::HostObject {
|
|
14
|
-
public:
|
|
15
|
-
DynamicHostObject() {};
|
|
16
|
-
|
|
17
|
-
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt);
|
|
18
|
-
|
|
19
|
-
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
|
|
20
|
-
|
|
21
|
-
std::vector<std::pair<std::string, JSVariant>> fields;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
#endif /* DynamicHostObject_h */
|