@aws-amplify/datastore-storage-adapter 2.0.71 → 2.0.73
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/.rollup.cache/Volumes/workplace/amplify-js/packages/datastore-storage-adapter/dist/meta/cjs.tsbuildinfo +1 -0
- package/CHANGELOG.md +12 -0
- package/coverage-ts/assets/source-file.css +21 -0
- package/coverage-ts/assets/source-file.js +40 -0
- package/coverage-ts/files/lib/ExpoSQLiteAdapter/ExpoSQLiteAdapter.d.ts.html +21 -0
- package/coverage-ts/files/lib/ExpoSQLiteAdapter/ExpoSQLiteDatabase.d.ts.html +35 -0
- package/coverage-ts/files/lib/SQLiteAdapter/SQLiteAdapter.d.ts.html +21 -0
- package/coverage-ts/files/lib/SQLiteAdapter/SQLiteDatabase.d.ts.html +35 -0
- package/coverage-ts/files/lib/common/CommonSQLiteAdapter.d.ts.html +41 -0
- package/coverage-ts/files/lib/common/SQLiteUtils.d.ts.html +39 -0
- package/coverage-ts/files/lib/common/constants.d.ts.html +19 -0
- package/coverage-ts/files/lib/common/types.d.ts.html +34 -0
- package/coverage-ts/files/lib/index.d.ts.html +20 -0
- package/coverage-ts/files/lib-esm/ExpoSQLiteAdapter/ExpoSQLiteAdapter.d.ts.html +21 -0
- package/coverage-ts/files/lib-esm/ExpoSQLiteAdapter/ExpoSQLiteDatabase.d.ts.html +35 -0
- package/coverage-ts/files/lib-esm/SQLiteAdapter/SQLiteAdapter.d.ts.html +21 -0
- package/coverage-ts/files/lib-esm/SQLiteAdapter/SQLiteDatabase.d.ts.html +35 -0
- package/coverage-ts/files/lib-esm/common/CommonSQLiteAdapter.d.ts.html +41 -0
- package/coverage-ts/files/lib-esm/common/SQLiteUtils.d.ts.html +39 -0
- package/coverage-ts/files/lib-esm/common/constants.d.ts.html +19 -0
- package/coverage-ts/files/lib-esm/common/types.d.ts.html +34 -0
- package/coverage-ts/files/lib-esm/index.d.ts.html +20 -0
- package/coverage-ts/files/src/ExpoSQLiteAdapter/ExpoSQLiteAdapter.ts.html +28 -0
- package/coverage-ts/files/src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts.html +302 -0
- package/coverage-ts/files/src/SQLiteAdapter/SQLiteAdapter.ts.html +28 -0
- package/coverage-ts/files/src/SQLiteAdapter/SQLiteDatabase.ts.html +183 -0
- package/coverage-ts/files/src/common/CommonSQLiteAdapter.ts.html +460 -0
- package/coverage-ts/files/src/common/SQLiteUtils.ts.html +520 -0
- package/coverage-ts/files/src/common/constants.ts.html +21 -0
- package/coverage-ts/files/src/common/types.ts.html +54 -0
- package/coverage-ts/files/src/index.ts.html +22 -0
- package/coverage-ts/index.html +15 -0
- package/coverage-ts/typescript-coverage.json +772 -0
- package/dist/aws-amplify-datastore-storage-adapter.js +5 -0
- package/dist/aws-amplify-datastore-storage-adapter.js.map +1 -1
- package/dist/aws-amplify-datastore-storage-adapter.min.js.map +1 -1
- package/lib/SQLiteAdapter/SQLiteAdapter.d.ts +5 -0
- package/lib/SQLiteAdapter/SQLiteAdapter.js +5 -0
- package/lib/SQLiteAdapter/SQLiteAdapter.js.map +1 -1
- package/lib-esm/SQLiteAdapter/SQLiteAdapter.d.ts +5 -0
- package/lib-esm/SQLiteAdapter/SQLiteAdapter.js +5 -0
- package/lib-esm/SQLiteAdapter/SQLiteAdapter.js.map +1 -1
- package/package.json +7 -4
- package/src/SQLiteAdapter/SQLiteAdapter.ts +5 -0
- package/.rollup.cache/home/runner/work/amplify-js/amplify-js/amplify-js/packages/datastore-storage-adapter/dist/meta/cjs.tsbuildinfo +0 -1
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/cjs/ExpoSQLiteAdapter/ExpoSQLiteAdapter.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/cjs/ExpoSQLiteAdapter/ExpoSQLiteDatabase.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/cjs/SQLiteAdapter/SQLiteAdapter.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/cjs/SQLiteAdapter/SQLiteDatabase.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/cjs/common/CommonSQLiteAdapter.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/cjs/common/SQLiteUtils.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/cjs/common/constants.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/cjs/common/types.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/cjs/index.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/ExpoSQLiteAdapter/ExpoSQLiteAdapter.d.ts +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/ExpoSQLiteAdapter/ExpoSQLiteAdapter.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/ExpoSQLiteAdapter/ExpoSQLiteDatabase.d.ts +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/ExpoSQLiteAdapter/ExpoSQLiteDatabase.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/SQLiteAdapter/SQLiteAdapter.d.ts +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/SQLiteAdapter/SQLiteAdapter.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/SQLiteAdapter/SQLiteDatabase.d.ts +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/SQLiteAdapter/SQLiteDatabase.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/common/CommonSQLiteAdapter.d.ts +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/common/CommonSQLiteAdapter.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/common/SQLiteUtils.d.ts +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/common/SQLiteUtils.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/common/constants.d.ts +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/common/constants.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/common/types.d.ts +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/common/types.js +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/index.d.ts +0 -0
- /package/.rollup.cache/{home/runner/work/amplify-js/amplify-js → Volumes/workplace}/amplify-js/packages/datastore-storage-adapter/dist/esm/index.js +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<title>index.d.ts</title>
|
|
6
|
+
<link href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css" type="text/css" rel="stylesheet">
|
|
7
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.js" type="text/javascript" charset="utf-8"></script>
|
|
8
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/mode/javascript/javascript.min.js" type="text/javascript" charset="utf-8"></script>
|
|
9
|
+
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.css" type="text/css" rel="stylesheet">
|
|
10
|
+
<script src="../../assets/source-file.js" type="text/javascript" charset="utf-8"></script>
|
|
11
|
+
<link href="../../assets/source-file.css" type="text/css" rel="stylesheet">
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div style="margin-top:3em" class="ui container"><h1 class="ui header"><a href="../../index.html">TypeScript coverage report</a></h1><table style="margin-top:2em" class="ui celled table"><thead class=""><tr class=""><th class="">Filename</th><th class="">Percent</th><th class="">Threshold</th><th class="">Total</th><th class="">Covered</th><th class="">Uncovered</th></tr></thead><tbody class=""><tr class="positive"><td class="">lib-esm/index.d.ts</td><td class="">100.00%</td><td class="">94.16%</td><td class="">2</td><td class="">2</td><td class="">0</td></tr></tbody></table><textarea id="editor" readonly="" style="margin-top:3em">import SQLiteAdapter from './SQLiteAdapter/SQLiteAdapter';
|
|
15
|
+
export { SQLiteAdapter };
|
|
16
|
+
</textarea><pre id="annotations" style="display:none">[]</pre></div>
|
|
17
|
+
<p class="footer-text">TypeScript Coverage Report generated by <a href="https://github.com/plantain-00/type-coverage">type-coverage</a> and <a href="https://github.com/alexcanessa/typescript-coverage-report">typescript-coverage-report</a> at Mon, 20 Apr 2026 10:42:30 GMT</p>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
20
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<title>ExpoSQLiteAdapter.ts</title>
|
|
6
|
+
<link href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css" type="text/css" rel="stylesheet">
|
|
7
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.js" type="text/javascript" charset="utf-8"></script>
|
|
8
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/mode/javascript/javascript.min.js" type="text/javascript" charset="utf-8"></script>
|
|
9
|
+
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.css" type="text/css" rel="stylesheet">
|
|
10
|
+
<script src="../../../assets/source-file.js" type="text/javascript" charset="utf-8"></script>
|
|
11
|
+
<link href="../../../assets/source-file.css" type="text/css" rel="stylesheet">
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div style="margin-top:3em" class="ui container"><h1 class="ui header"><a href="../../../index.html">TypeScript coverage report</a></h1><table style="margin-top:2em" class="ui celled table"><thead class=""><tr class=""><th class="">Filename</th><th class="">Percent</th><th class="">Threshold</th><th class="">Total</th><th class="">Covered</th><th class="">Uncovered</th></tr></thead><tbody class=""><tr class="positive"><td class="">src/ExpoSQLiteAdapter/ExpoSQLiteAdapter.ts</td><td class="">100.00%</td><td class="">94.16%</td><td class="">7</td><td class="">7</td><td class="">0</td></tr></tbody></table><textarea id="editor" readonly="" style="margin-top:3em">// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
15
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
import { CommonSQLiteAdapter } from '../common/CommonSQLiteAdapter';
|
|
17
|
+
import ExpoSQLiteDatabase from './ExpoSQLiteDatabase';
|
|
18
|
+
|
|
19
|
+
const ExpoSQLiteAdapter: CommonSQLiteAdapter = new CommonSQLiteAdapter(
|
|
20
|
+
new ExpoSQLiteDatabase()
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export default ExpoSQLiteAdapter;
|
|
24
|
+
</textarea><pre id="annotations" style="display:none">[]</pre></div>
|
|
25
|
+
<p class="footer-text">TypeScript Coverage Report generated by <a href="https://github.com/plantain-00/type-coverage">type-coverage</a> and <a href="https://github.com/alexcanessa/typescript-coverage-report">typescript-coverage-report</a> at Mon, 20 Apr 2026 10:42:30 GMT</p>
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
|
28
|
+
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<title>ExpoSQLiteDatabase.ts</title>
|
|
6
|
+
<link href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css" type="text/css" rel="stylesheet">
|
|
7
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.js" type="text/javascript" charset="utf-8"></script>
|
|
8
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/mode/javascript/javascript.min.js" type="text/javascript" charset="utf-8"></script>
|
|
9
|
+
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.css" type="text/css" rel="stylesheet">
|
|
10
|
+
<script src="../../../assets/source-file.js" type="text/javascript" charset="utf-8"></script>
|
|
11
|
+
<link href="../../../assets/source-file.css" type="text/css" rel="stylesheet">
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div style="margin-top:3em" class="ui container"><h1 class="ui header"><a href="../../../index.html">TypeScript coverage report</a></h1><table style="margin-top:2em" class="ui celled table"><thead class=""><tr class=""><th class="">Filename</th><th class="">Percent</th><th class="">Threshold</th><th class="">Total</th><th class="">Covered</th><th class="">Uncovered</th></tr></thead><tbody class=""><tr class="positive"><td class="">src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts</td><td class="">95.36%</td><td class="">94.16%</td><td class="">345</td><td class="">329</td><td class="">16</td></tr></tbody></table><textarea id="editor" readonly="" style="margin-top:3em">// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
15
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
17
|
+
import { PersistentModel } from '@aws-amplify/datastore';
|
|
18
|
+
import { deleteAsync, documentDirectory } from 'expo-file-system';
|
|
19
|
+
import { openDatabase, WebSQLDatabase } from 'expo-sqlite';
|
|
20
|
+
import { DB_NAME } from '../common/constants';
|
|
21
|
+
import { CommonSQLiteDatabase, ParameterizedStatement } from '../common/types';
|
|
22
|
+
|
|
23
|
+
const logger = new Logger('ExpoSQLiteDatabase');
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
|
|
27
|
+
Note:
|
|
28
|
+
ExpoSQLite transaction error callbacks require returning a boolean value to indicate whether the
|
|
29
|
+
error was handled or not. Returning a true value indicates the error was handled and does not
|
|
30
|
+
rollback the whole transaction.
|
|
31
|
+
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
class ExpoSQLiteDatabase implements CommonSQLiteDatabase {
|
|
35
|
+
private db: WebSQLDatabase;
|
|
36
|
+
|
|
37
|
+
public async init(): Promise<void> {
|
|
38
|
+
// only open database once.
|
|
39
|
+
|
|
40
|
+
if (!this.db) {
|
|
41
|
+
// As per expo docs version, description and size arguments are ignored,
|
|
42
|
+
// but are accepted by the function for compatibility with the WebSQL specification.
|
|
43
|
+
// Hence, we do not need those arguments.
|
|
44
|
+
this.db = openDatabase(DB_NAME);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public createSchema(statements: string[]): Promise<void> {
|
|
49
|
+
return this.executeStatements(statements);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public async clear(): Promise<void> {
|
|
53
|
+
try {
|
|
54
|
+
logger.debug('Clearing database');
|
|
55
|
+
await this.closeDB();
|
|
56
|
+
// delete database is not supported by expo-sqlite.
|
|
57
|
+
// Database file needs to be deleted using deleteAsync from expo-file-system
|
|
58
|
+
await deleteAsync(`${documentDirectory}SQLite/${DB_NAME}`);
|
|
59
|
+
logger.debug('Database cleared');
|
|
60
|
+
} catch (error) {
|
|
61
|
+
logger.warn('Error clearing the database.', error);
|
|
62
|
+
// open database if it was closed earlier and this.db was set to undefined.
|
|
63
|
+
this.init();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public async get<T extends PersistentModel>(
|
|
68
|
+
statement: string,
|
|
69
|
+
params: (string | number)[]
|
|
70
|
+
): Promise<T> {
|
|
71
|
+
const results: T[] = await this.getAll(statement, params);
|
|
72
|
+
return results[0];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public getAll<T extends PersistentModel>(
|
|
76
|
+
statement: string,
|
|
77
|
+
params: (string | number)[]
|
|
78
|
+
): Promise<T[]> {
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
this.db.readTransaction(transaction => {
|
|
81
|
+
transaction.executeSql(
|
|
82
|
+
statement,
|
|
83
|
+
params,
|
|
84
|
+
(_, result) => {
|
|
85
|
+
resolve(result.rows._array || []);
|
|
86
|
+
},
|
|
87
|
+
(_, error) => {
|
|
88
|
+
reject(error);
|
|
89
|
+
logger.warn(error);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public save(statement: string, params: (string | number)[]): Promise<void> {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
this.db.transaction(transaction => {
|
|
100
|
+
transaction.executeSql(
|
|
101
|
+
statement,
|
|
102
|
+
params,
|
|
103
|
+
() => {
|
|
104
|
+
resolve(null);
|
|
105
|
+
},
|
|
106
|
+
(_, error) => {
|
|
107
|
+
reject(error);
|
|
108
|
+
logger.warn(error);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public batchQuery<T = any>(
|
|
117
|
+
queryParameterizedStatements: Set<ParameterizedStatement> = new Set()
|
|
118
|
+
): Promise<T[]> {
|
|
119
|
+
return new Promise((resolveTransaction, rejectTransaction) => {
|
|
120
|
+
this.db.transaction(async transaction => {
|
|
121
|
+
try {
|
|
122
|
+
const results: any[] = await Promise.all(
|
|
123
|
+
[...queryParameterizedStatements].map(
|
|
124
|
+
([statement, params]) =>
|
|
125
|
+
new Promise((resolve, reject) => {
|
|
126
|
+
transaction.executeSql(
|
|
127
|
+
statement,
|
|
128
|
+
params,
|
|
129
|
+
(_, result) => {
|
|
130
|
+
resolve(result.rows._array[0]);
|
|
131
|
+
},
|
|
132
|
+
(_, error) => {
|
|
133
|
+
reject(error);
|
|
134
|
+
logger.warn(error);
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
})
|
|
139
|
+
)
|
|
140
|
+
);
|
|
141
|
+
resolveTransaction(results);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
rejectTransaction(error);
|
|
144
|
+
logger.warn(error);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public batchSave(
|
|
151
|
+
saveParameterizedStatements: Set<ParameterizedStatement> = new Set(),
|
|
152
|
+
deleteParameterizedStatements?: Set<ParameterizedStatement>
|
|
153
|
+
): Promise<void> {
|
|
154
|
+
return new Promise((resolveTransaction, rejectTransaction) => {
|
|
155
|
+
this.db.transaction(async transaction => {
|
|
156
|
+
try {
|
|
157
|
+
// await for all sql statements promises to resolve
|
|
158
|
+
await Promise.all(
|
|
159
|
+
[...saveParameterizedStatements].map(
|
|
160
|
+
([statement, params]) =>
|
|
161
|
+
new Promise((resolve, reject) => {
|
|
162
|
+
transaction.executeSql(
|
|
163
|
+
statement,
|
|
164
|
+
params,
|
|
165
|
+
() => {
|
|
166
|
+
resolve(null);
|
|
167
|
+
},
|
|
168
|
+
(_, error) => {
|
|
169
|
+
reject(error);
|
|
170
|
+
logger.warn(error);
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
})
|
|
175
|
+
)
|
|
176
|
+
);
|
|
177
|
+
if (deleteParameterizedStatements) {
|
|
178
|
+
await Promise.all(
|
|
179
|
+
[...deleteParameterizedStatements].map(
|
|
180
|
+
([statement, params]) =>
|
|
181
|
+
new Promise((resolve, reject) =>
|
|
182
|
+
transaction.executeSql(
|
|
183
|
+
statement,
|
|
184
|
+
params,
|
|
185
|
+
() => {
|
|
186
|
+
resolve(null);
|
|
187
|
+
},
|
|
188
|
+
(_, error) => {
|
|
189
|
+
reject(error);
|
|
190
|
+
logger.warn(error);
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
)
|
|
195
|
+
)
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
resolveTransaction(null);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
rejectTransaction(error);
|
|
201
|
+
logger.warn(error);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public selectAndDelete<T = any>(
|
|
208
|
+
queryParameterizedStatement: ParameterizedStatement,
|
|
209
|
+
deleteParameterizedStatement: ParameterizedStatement
|
|
210
|
+
): Promise<T[]> {
|
|
211
|
+
const [queryStatement, queryParams] = queryParameterizedStatement;
|
|
212
|
+
const [deleteStatement, deleteParams] = deleteParameterizedStatement;
|
|
213
|
+
|
|
214
|
+
return new Promise((resolveTransaction, rejectTransaction) => {
|
|
215
|
+
this.db.transaction(async transaction => {
|
|
216
|
+
try {
|
|
217
|
+
const result: T[] = await new Promise((resolve, reject) => {
|
|
218
|
+
transaction.executeSql(
|
|
219
|
+
queryStatement,
|
|
220
|
+
queryParams,
|
|
221
|
+
(_, result) => {
|
|
222
|
+
resolve(result.rows._array || []);
|
|
223
|
+
},
|
|
224
|
+
(_, error) => {
|
|
225
|
+
reject(error);
|
|
226
|
+
logger.warn(error);
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
await new Promise((resolve, reject) => {
|
|
232
|
+
transaction.executeSql(
|
|
233
|
+
deleteStatement,
|
|
234
|
+
deleteParams,
|
|
235
|
+
() => {
|
|
236
|
+
resolve(null);
|
|
237
|
+
},
|
|
238
|
+
(_, error) => {
|
|
239
|
+
reject(error);
|
|
240
|
+
logger.warn(error);
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
);
|
|
244
|
+
});
|
|
245
|
+
resolveTransaction(result);
|
|
246
|
+
} catch (error) {
|
|
247
|
+
rejectTransaction(error);
|
|
248
|
+
logger.warn(error);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private executeStatements(statements: string[]): Promise<void> {
|
|
255
|
+
return new Promise((resolveTransaction, rejectTransaction) => {
|
|
256
|
+
this.db.transaction(async transaction => {
|
|
257
|
+
try {
|
|
258
|
+
await Promise.all(
|
|
259
|
+
statements.map(
|
|
260
|
+
statement =>
|
|
261
|
+
new Promise((resolve, reject) => {
|
|
262
|
+
transaction.executeSql(
|
|
263
|
+
statement,
|
|
264
|
+
[],
|
|
265
|
+
() => {
|
|
266
|
+
resolve(null);
|
|
267
|
+
},
|
|
268
|
+
(_, error) => {
|
|
269
|
+
reject(error);
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
);
|
|
273
|
+
})
|
|
274
|
+
)
|
|
275
|
+
);
|
|
276
|
+
resolveTransaction(null);
|
|
277
|
+
} catch (error) {
|
|
278
|
+
rejectTransaction(error);
|
|
279
|
+
logger.warn(error);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private async closeDB() {
|
|
286
|
+
if (this.db) {
|
|
287
|
+
logger.debug('Closing Database');
|
|
288
|
+
// closing database is not supported by expo-sqlite.
|
|
289
|
+
// Workaround is to access the private db variable and call the close() method.
|
|
290
|
+
await (this.db as any)._db.close();
|
|
291
|
+
logger.debug('Database closed');
|
|
292
|
+
this.db = undefined;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export default ExpoSQLiteDatabase;
|
|
298
|
+
</textarea><pre id="annotations" style="display:none">[{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":47,"character":47,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":46,"character":11,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":129,"character":23,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":130,"character":17,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":128,"character":13,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":186,"character":23,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":187,"character":17,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":185,"character":13,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":233,"character":23,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":234,"character":17,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":232,"character":13,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":264,"character":23,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":265,"character":17,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":263,"character":13,"text":"error","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":276,"character":26,"text":"_db","kind":1},{"file":"src/ExpoSQLiteAdapter/ExpoSQLiteDatabase.ts","line":276,"character":30,"text":"close","kind":1}]</pre></div>
|
|
299
|
+
<p class="footer-text">TypeScript Coverage Report generated by <a href="https://github.com/plantain-00/type-coverage">type-coverage</a> and <a href="https://github.com/alexcanessa/typescript-coverage-report">typescript-coverage-report</a> at Mon, 20 Apr 2026 10:42:30 GMT</p>
|
|
300
|
+
</body>
|
|
301
|
+
</html>
|
|
302
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<title>SQLiteAdapter.ts</title>
|
|
6
|
+
<link href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css" type="text/css" rel="stylesheet">
|
|
7
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.js" type="text/javascript" charset="utf-8"></script>
|
|
8
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/mode/javascript/javascript.min.js" type="text/javascript" charset="utf-8"></script>
|
|
9
|
+
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.css" type="text/css" rel="stylesheet">
|
|
10
|
+
<script src="../../../assets/source-file.js" type="text/javascript" charset="utf-8"></script>
|
|
11
|
+
<link href="../../../assets/source-file.css" type="text/css" rel="stylesheet">
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div style="margin-top:3em" class="ui container"><h1 class="ui header"><a href="../../../index.html">TypeScript coverage report</a></h1><table style="margin-top:2em" class="ui celled table"><thead class=""><tr class=""><th class="">Filename</th><th class="">Percent</th><th class="">Threshold</th><th class="">Total</th><th class="">Covered</th><th class="">Uncovered</th></tr></thead><tbody class=""><tr class="positive"><td class="">src/SQLiteAdapter/SQLiteAdapter.ts</td><td class="">100.00%</td><td class="">94.16%</td><td class="">7</td><td class="">7</td><td class="">0</td></tr></tbody></table><textarea id="editor" readonly="" style="margin-top:3em">// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
15
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
import { CommonSQLiteAdapter } from '../common/CommonSQLiteAdapter';
|
|
17
|
+
import SQLiteDatabase from './SQLiteDatabase';
|
|
18
|
+
|
|
19
|
+
const SQLiteAdapter: CommonSQLiteAdapter = new CommonSQLiteAdapter(
|
|
20
|
+
new SQLiteDatabase()
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export default SQLiteAdapter;
|
|
24
|
+
</textarea><pre id="annotations" style="display:none">[]</pre></div>
|
|
25
|
+
<p class="footer-text">TypeScript Coverage Report generated by <a href="https://github.com/plantain-00/type-coverage">type-coverage</a> and <a href="https://github.com/alexcanessa/typescript-coverage-report">typescript-coverage-report</a> at Mon, 20 Apr 2026 10:42:30 GMT</p>
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
|
28
|
+
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<title>SQLiteDatabase.ts</title>
|
|
6
|
+
<link href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css" type="text/css" rel="stylesheet">
|
|
7
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.js" type="text/javascript" charset="utf-8"></script>
|
|
8
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/mode/javascript/javascript.min.js" type="text/javascript" charset="utf-8"></script>
|
|
9
|
+
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.css" type="text/css" rel="stylesheet">
|
|
10
|
+
<script src="../../../assets/source-file.js" type="text/javascript" charset="utf-8"></script>
|
|
11
|
+
<link href="../../../assets/source-file.css" type="text/css" rel="stylesheet">
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div style="margin-top:3em" class="ui container"><h1 class="ui header"><a href="../../../index.html">TypeScript coverage report</a></h1><table style="margin-top:2em" class="ui celled table"><thead class=""><tr class=""><th class="">Filename</th><th class="">Percent</th><th class="">Threshold</th><th class="">Total</th><th class="">Covered</th><th class="">Uncovered</th></tr></thead><tbody class=""><tr class="positive"><td class="">src/SQLiteAdapter/SQLiteDatabase.ts</td><td class="">99.56%</td><td class="">94.16%</td><td class="">225</td><td class="">224</td><td class="">1</td></tr></tbody></table><textarea id="editor" readonly="" style="margin-top:3em">// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
15
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
import SQLite from 'react-native-sqlite-storage';
|
|
17
|
+
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
18
|
+
import { PersistentModel } from '@aws-amplify/datastore';
|
|
19
|
+
import { DB_NAME } from '../common/constants';
|
|
20
|
+
import { CommonSQLiteDatabase, ParameterizedStatement } from '../common/types';
|
|
21
|
+
|
|
22
|
+
const logger = new Logger('SQLiteDatabase');
|
|
23
|
+
|
|
24
|
+
SQLite.enablePromise(true);
|
|
25
|
+
|
|
26
|
+
if (Logger.LOG_LEVEL === 'DEBUG') {
|
|
27
|
+
SQLite.DEBUG(true);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
|
|
32
|
+
Note:
|
|
33
|
+
I purposely avoided using arrow functions () => {} in this class,
|
|
34
|
+
Because I ran into issues with them in some of the SQLite method callbacks
|
|
35
|
+
|
|
36
|
+
Also, even though the SQLite library is promisified, certain operations
|
|
37
|
+
only work correctly with callbacks. Specifically, any time you need to
|
|
38
|
+
get the result of an `executeSql` command inside of a transaction
|
|
39
|
+
(see the batchQuery method below)
|
|
40
|
+
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
class SQLiteDatabase implements CommonSQLiteDatabase {
|
|
44
|
+
private db: SQLite.SQLiteDatabase;
|
|
45
|
+
|
|
46
|
+
public async init(): Promise<void> {
|
|
47
|
+
// only open database once.
|
|
48
|
+
if (!this.db) {
|
|
49
|
+
this.db = await SQLite.openDatabase({
|
|
50
|
+
name: DB_NAME,
|
|
51
|
+
location: 'default',
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public async createSchema(statements: string[]): Promise<void> {
|
|
57
|
+
return await this.executeStatements(statements);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public async clear(): Promise<void> {
|
|
61
|
+
await this.closeDB();
|
|
62
|
+
logger.debug('Deleting database');
|
|
63
|
+
await SQLite.deleteDatabase({ name: DB_NAME, location: 'default' });
|
|
64
|
+
logger.debug('Database deleted');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public async get<T extends PersistentModel>(
|
|
68
|
+
statement: string,
|
|
69
|
+
params: (string | number)[]
|
|
70
|
+
): Promise<T> {
|
|
71
|
+
const results: T[] = await this.getAll(statement, params);
|
|
72
|
+
return results[0];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public async getAll<T extends PersistentModel>(
|
|
76
|
+
statement: string,
|
|
77
|
+
params: (string | number)[]
|
|
78
|
+
): Promise<T[]> {
|
|
79
|
+
const [resultSet] = await this.db.executeSql(statement, params);
|
|
80
|
+
const result =
|
|
81
|
+
resultSet &&
|
|
82
|
+
resultSet.rows &&
|
|
83
|
+
resultSet.rows.length &&
|
|
84
|
+
resultSet.rows.raw &&
|
|
85
|
+
resultSet.rows.raw();
|
|
86
|
+
|
|
87
|
+
return result || [];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public async save(
|
|
91
|
+
statement: string,
|
|
92
|
+
params: (string | number)[]
|
|
93
|
+
): Promise<void> {
|
|
94
|
+
await this.db.executeSql(statement, params);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public async batchQuery<T = any>(
|
|
98
|
+
queryParameterizedStatements: Set<ParameterizedStatement>
|
|
99
|
+
): Promise<T[]> {
|
|
100
|
+
const results = [];
|
|
101
|
+
|
|
102
|
+
await this.db.readTransaction(tx => {
|
|
103
|
+
for (const [statement, params] of queryParameterizedStatements) {
|
|
104
|
+
tx.executeSql(
|
|
105
|
+
statement,
|
|
106
|
+
params,
|
|
107
|
+
(_, res) => {
|
|
108
|
+
results.push(res.rows.raw()[0]);
|
|
109
|
+
},
|
|
110
|
+
logger.warn
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return results;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public async batchSave(
|
|
119
|
+
saveParameterizedStatements: Set<ParameterizedStatement>,
|
|
120
|
+
deleteParameterizedStatements?: Set<ParameterizedStatement>
|
|
121
|
+
): Promise<void> {
|
|
122
|
+
await this.db.transaction(tx => {
|
|
123
|
+
for (const [statement, params] of saveParameterizedStatements) {
|
|
124
|
+
tx.executeSql(statement, params);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
if (deleteParameterizedStatements) {
|
|
128
|
+
await this.db.transaction(tx => {
|
|
129
|
+
for (const [statement, params] of deleteParameterizedStatements) {
|
|
130
|
+
tx.executeSql(statement, params);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public async selectAndDelete<T = any>(
|
|
137
|
+
queryParameterizedStatement: ParameterizedStatement,
|
|
138
|
+
deleteParameterizedStatement: ParameterizedStatement
|
|
139
|
+
): Promise<T[]> {
|
|
140
|
+
let results: T[] = [];
|
|
141
|
+
|
|
142
|
+
const [queryStatement, queryParams] = queryParameterizedStatement;
|
|
143
|
+
const [deleteStatement, deleteParams] = deleteParameterizedStatement;
|
|
144
|
+
|
|
145
|
+
await this.db.transaction(tx => {
|
|
146
|
+
tx.executeSql(
|
|
147
|
+
queryStatement,
|
|
148
|
+
queryParams,
|
|
149
|
+
(_, res) => {
|
|
150
|
+
results = res.rows.raw();
|
|
151
|
+
},
|
|
152
|
+
logger.warn
|
|
153
|
+
);
|
|
154
|
+
tx.executeSql(deleteStatement, deleteParams, () => {}, logger.warn);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return results;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private async executeStatements(statements: string[]): Promise<void> {
|
|
161
|
+
await this.db.transaction(tx => {
|
|
162
|
+
for (const statement of statements) {
|
|
163
|
+
tx.executeSql(statement);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private async closeDB() {
|
|
169
|
+
if (this.db) {
|
|
170
|
+
logger.debug('Closing Database');
|
|
171
|
+
await this.db.close();
|
|
172
|
+
logger.debug('Database closed');
|
|
173
|
+
this.db = undefined;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export default SQLiteDatabase;
|
|
179
|
+
</textarea><pre id="annotations" style="display:none">[{"file":"src/SQLiteAdapter/SQLiteDatabase.ts","line":12,"character":11,"text":"LOG_LEVEL","kind":1}]</pre></div>
|
|
180
|
+
<p class="footer-text">TypeScript Coverage Report generated by <a href="https://github.com/plantain-00/type-coverage">type-coverage</a> and <a href="https://github.com/alexcanessa/typescript-coverage-report">typescript-coverage-report</a> at Mon, 20 Apr 2026 10:42:30 GMT</p>
|
|
181
|
+
</body>
|
|
182
|
+
</html>
|
|
183
|
+
|