Skip to content

Commit 7b35845

Browse files
committed
[rn] Implementation
1 parent 63b5f8a commit 7b35845

File tree

1 file changed

+33
-0
lines changed
  • src/persisters/persister-react-native-sqlite

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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

Comments
 (0)