|
| 1 | +import type {MergeableStore} from '../../@types/mergeable-store/index.js'; |
| 2 | +import type {DatabasePersisterConfig} from '../../@types/persisters/index.js'; |
| 3 | +import type { |
| 4 | + ReactNativeSqlitePersister, |
| 5 | + createReactNativeSqlitePersister as createReactNativeSqlitePersisterDecl, |
| 6 | +} from '../../@types/persisters/persister-react-native-sqlite/index.js'; |
| 7 | +import type {Store} from '../../@types/store/index.js'; |
| 8 | +import {IdObj} from '../../common/obj.ts'; |
| 9 | +import {noop} from '../../common/other.ts'; |
| 10 | +import {createCustomSqlitePersister} from '../common/database/sqlite.ts'; |
| 11 | + |
| 12 | +import {type SQLiteDatabase} from 'react-native-sqlite-storage'; |
| 13 | + |
| 14 | +export const createReactNativeSqlitePersister = (( |
| 15 | + store: Store | MergeableStore, |
| 16 | + db: SQLiteDatabase, |
| 17 | + configOrStoreTableName?: DatabasePersisterConfig | string, |
| 18 | + onSqlCommand?: (sql: string, params?: any[]) => void, |
| 19 | + onIgnoredError?: (error: any) => void, |
| 20 | +): ReactNativeSqlitePersister => |
| 21 | + createCustomSqlitePersister( |
| 22 | + store, |
| 23 | + configOrStoreTableName, |
| 24 | + async (sql: string, params: any[] = []): Promise<IdObj<any>[]> => |
| 25 | + (await db.executeSql(sql, params))[0].rows.raw(), |
| 26 | + noop, |
| 27 | + noop, |
| 28 | + onSqlCommand, |
| 29 | + onIgnoredError, |
| 30 | + noop, |
| 31 | + 3, // StoreOrMergeableStore, |
| 32 | + db, |
| 33 | + ) as ReactNativeSqlitePersister) as typeof createReactNativeSqlitePersisterDecl; |
0 commit comments