forked from andpor/react-native-sqlite-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeSQLitePlugin.ts
More file actions
100 lines (85 loc) · 3.07 KB
/
Copy pathNativeSQLitePlugin.ts
File metadata and controls
100 lines (85 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
interface DatabaseOptionalParams {
createFromLocation?: string;
// Database encryption pass phrase
key?: string;
readOnly?: boolean;
}
interface DatabaseParams extends DatabaseOptionalParams {
name: string;
/**
* Affects iOS database file location
* 'default': Library/LocalDatabase subdirectory - NOT visible to iTunes and NOT backed up by iCloud
* 'Library': Library subdirectory - backed up by iCloud, NOT visible to iTunes
* 'Documents': Documents subdirectory - visible to iTunes and backed up by iCloud
*/
location: string;
}
interface ResultSet {
insertId: number;
rowsAffected: number;
rows: ResultSetRowList;
}
interface ResultSetRowList {
length: number;
raw(): any[];
item(index: number): any;
}
enum SQLErrors {
UNKNOWN_ERR = 0,
DATABASE_ERR = 1,
VERSION_ERR = 2,
TOO_LARGE_ERR = 3,
QUOTA_ERR = 4,
SYNTAX_ERR = 5,
CONSTRAINT_ERR = 6,
TIMEOUT_ERR = 7,
}
interface SQLError {
code: number;
message: string;
}
type StatementCallback = (transaction: Transaction, resultSet: ResultSet) => void;
type StatementErrorCallback = (transaction: Transaction, error: SQLError) => void;
interface Transaction {
executeSql(sqlStatement: string, arguments?: any[]): Promise<[Transaction, ResultSet]>;
executeSql(
sqlStatement: string,
arguments?: any[],
callback?: StatementCallback,
errorCallback?: StatementErrorCallback,
): void;
}
type TransactionCallback = (transaction: Transaction) => void;
type TransactionErrorCallback = (error: SQLError) => void;
interface SQLiteDatabase {
dbname: string;
transaction(scope: (tx: Transaction) => void): Promise<Transaction>;
transaction(
scope: (tx: Transaction) => void,
error?: TransactionErrorCallback,
success?: TransactionCallback,
): void;
readTransaction(scope: (tx: Transaction) => void): Promise<Transaction>;
readTransaction(
scope: (tx: Transaction) => void,
error?: TransactionErrorCallback,
success?: TransactionCallback,
): void;
close(): Promise<void>;
close(success: () => void, error: (err: SQLError) => void): void;
executeSql(statement: string, params?: any[]): Promise<[ResultSet]>;
executeSql(statement: string, params?: any[], success?: StatementCallback, error?: StatementErrorCallback): void;
attach(nameToAttach: string, alias: string): Promise<void>;
attach(nameToAttach: string, alias: string, success?: () => void, error?: (err: SQLError) => void): void;
detach(alias: string): Promise<void>;
detach(alias: string, success?: () => void, error?: (err: SQLError) => void): void;
}
export interface Spec extends TurboModule {
debug(isDebug: boolean): void;
enablePromise(enablePromise: boolean): void;
openDatabase(params: DatabaseParams): Promise<SQLiteDatabase>;
deleteDatabase(params: DatabaseParams): Promise<void>;
}
export default TurboModuleRegistry.getEnforcing<Spec>('SQLite');