@journeyapps/react-native-quick-sqlite
Version:
Fast SQLite for react-native
49 lines (38 loc) • 1.78 kB
text/typescript
import { NativeModules } from 'react-native';
import { ISQLite } from './types';
import { setupOpen } from './setup-open';
import { setupTypeORMDriver } from './type-orm';
export * from './types';
declare global {
function nativeCallSyncHook(): unknown;
var __QuickSQLiteProxy: object | undefined;
}
if (global.__QuickSQLiteProxy == null) {
const QuickSQLiteModule = NativeModules.QuickSQLite;
if (QuickSQLiteModule == null) {
throw new Error('Base quick-sqlite module not found. Maybe try rebuilding the app.');
}
// Check if we are running on-device (JSI)
if (QuickSQLiteModule.install == null) {
throw new Error(
'Failed to install react-native-quick-sqlite: React Native is not running on-device. QuickSQLite 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.'
);
}
// Call the synchronous blocking install() function
const result = QuickSQLiteModule.install();
if (result !== true) {
throw new Error(
`Failed to install react-native-quick-sqlite: The native QuickSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`
);
}
// Check again if the constructor now exists. If not, throw an error.
if (global.__QuickSQLiteProxy == null) {
throw new Error(
'Failed to install react-native-quick-sqlite, the native initializer function does not exist. Are you trying to use QuickSQLite from different JS Runtimes?'
);
}
}
const proxy = global.__QuickSQLiteProxy;
export const QuickSQLite = proxy as ISQLite;
export const { open } = setupOpen(QuickSQLite);
export const typeORMDriver = setupTypeORMDriver(open);