@capacitor-community/sqlite 3.4.1-1 → 3.4.1-4
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/README.md +24 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +14 -6
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +24 -11
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +5 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +24 -15
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/UtilsJson.java +23 -0
- package/electron/dist/plugin.js +265 -198
- package/electron/dist/plugin.js.map +1 -1
- package/electron/rollup.config.js +18 -2
- package/ios/Plugin/BiometricIDAuthentication.swift +3 -0
- package/ios/Plugin/CapacitorSQLite.swift +4 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +2 -0
- package/ios/Plugin/Database.swift +32 -9
- package/ios/Plugin/ImportExportJson/ExportToJson.swift +8 -0
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +20 -14
- package/ios/Plugin/Utils/UtilsJson.swift +28 -0
- package/package.json +4 -1
|
@@ -12,6 +12,22 @@ export default {
|
|
|
12
12
|
exports: 'named',
|
|
13
13
|
},
|
|
14
14
|
],
|
|
15
|
-
external: [
|
|
16
|
-
|
|
15
|
+
external: [
|
|
16
|
+
'@capacitor/core',
|
|
17
|
+
'electron',
|
|
18
|
+
'sqlite3',
|
|
19
|
+
'path',
|
|
20
|
+
'fs',
|
|
21
|
+
'os',
|
|
22
|
+
'jszip',
|
|
23
|
+
],
|
|
24
|
+
plugins: [
|
|
25
|
+
nodeResolve(),
|
|
26
|
+
commonjs({
|
|
27
|
+
ignoreDynamicRequires: true,
|
|
28
|
+
dynamicRequireTargets: [
|
|
29
|
+
'node_modules/@capacitor-community/sqlite/electron/dist/plugin.js',
|
|
30
|
+
],
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
17
33
|
};
|
|
@@ -44,6 +44,7 @@ class BiometricIDAuthentication {
|
|
|
44
44
|
throw BiometricIDAuthenticationError.biometricType(message: msg)
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
// swiftlint:disable no_space_in_method_call
|
|
47
48
|
func authenticateUser(completion: @escaping (String?) -> Void) {
|
|
48
49
|
let context = LAContext()
|
|
49
50
|
context.touchIDAuthenticationAllowableReuseDuration = 10
|
|
@@ -76,4 +77,6 @@ class BiometricIDAuthentication {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
}
|
|
80
|
+
// swiftlint:enable no_space_in_method_call
|
|
81
|
+
|
|
79
82
|
}
|
|
@@ -26,6 +26,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
26
26
|
|
|
27
27
|
// swiftlint:disable function_body_length
|
|
28
28
|
// swiftlint:disable cyclomatic_complexity
|
|
29
|
+
// swiftlint:disable no_space_in_method_call
|
|
29
30
|
init(config: SqliteConfig) {
|
|
30
31
|
self.config = config
|
|
31
32
|
super.init()
|
|
@@ -97,6 +98,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
97
98
|
isInit = true
|
|
98
99
|
}
|
|
99
100
|
}
|
|
101
|
+
// swiftlint:enable no_space_in_method_call
|
|
100
102
|
// swiftlint:enable cyclomatic_complexity
|
|
101
103
|
// swiftlint:enable function_body_length
|
|
102
104
|
|
|
@@ -160,6 +162,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
160
162
|
// MARK: - ChangeEncryptionSecret
|
|
161
163
|
|
|
162
164
|
// swiftlint:disable function_body_length
|
|
165
|
+
// swiftlint:disable no_space_in_method_call
|
|
163
166
|
@objc public func changeEncryptionSecret(call: CAPPluginCall, passphrase: String,
|
|
164
167
|
oldPassphrase: String) throws {
|
|
165
168
|
if isInit {
|
|
@@ -225,6 +228,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
225
228
|
}
|
|
226
229
|
|
|
227
230
|
}
|
|
231
|
+
// swiftlint:enable no_space_in_method_call
|
|
228
232
|
// swiftlint:enable function_body_length
|
|
229
233
|
|
|
230
234
|
// MARK: - getNCDatabasePath
|
|
@@ -1192,6 +1192,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
|
|
|
1192
1192
|
|
|
1193
1193
|
// MARK: - Handle Notifications
|
|
1194
1194
|
|
|
1195
|
+
// swiftlint:disable no_space_in_method_call
|
|
1195
1196
|
@objc func importJsonProgress(notification: Notification) {
|
|
1196
1197
|
guard let info = notification.userInfo as? [String: Any] else { return }
|
|
1197
1198
|
DispatchQueue.main.async {
|
|
@@ -1213,6 +1214,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
|
|
|
1213
1214
|
return
|
|
1214
1215
|
}
|
|
1215
1216
|
}
|
|
1217
|
+
// swiftlint:enable no_space_in_method_call
|
|
1216
1218
|
private func sqliteConfig() -> SqliteConfig {
|
|
1217
1219
|
var config = SqliteConfig()
|
|
1218
1220
|
config.iosIsEncryption = 1
|
|
@@ -453,18 +453,27 @@ class Database {
|
|
|
453
453
|
let isExists: Bool = try UtilsJson.isTableExists(
|
|
454
454
|
mDB: self, tableName: "sync_table")
|
|
455
455
|
if !isExists {
|
|
456
|
-
|
|
457
|
-
let
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
456
|
+
// check if there are tables with last_modified column
|
|
457
|
+
let isLastModified: Bool = try UtilsJson.isLastModified(mDB: self)
|
|
458
|
+
if isLastModified {
|
|
459
|
+
let date = Date()
|
|
460
|
+
let syncTime: Int = Int(date.timeIntervalSince1970)
|
|
461
|
+
var stmt: String = "CREATE TABLE IF NOT EXISTS "
|
|
462
|
+
stmt.append("sync_table (")
|
|
463
|
+
stmt.append("id INTEGER PRIMARY KEY NOT NULL,")
|
|
464
|
+
stmt.append("sync_date INTEGER);")
|
|
465
|
+
stmt.append("INSERT INTO sync_table (sync_date) ")
|
|
466
|
+
stmt.append("VALUES ('\(syncTime)');")
|
|
467
|
+
retObj = try executeSQL(sql: stmt)
|
|
468
|
+
} else {
|
|
469
|
+
let msg = "No last_modified column in tables"
|
|
470
|
+
throw DatabaseError.createSyncTable(message: msg)
|
|
471
|
+
}
|
|
465
472
|
} else {
|
|
466
473
|
retObj = 0
|
|
467
474
|
}
|
|
475
|
+
} catch UtilsJsonError.isLastModified(let message) {
|
|
476
|
+
throw DatabaseError.createSyncTable(message: message)
|
|
468
477
|
} catch UtilsJsonError.tableNotExists(let message) {
|
|
469
478
|
throw DatabaseError.createSyncTable(message: message)
|
|
470
479
|
} catch DatabaseError.executeSQL(let message) {
|
|
@@ -478,6 +487,11 @@ class Database {
|
|
|
478
487
|
func setSyncDate(syncDate: String ) throws -> Bool {
|
|
479
488
|
var retBool: Bool = false
|
|
480
489
|
do {
|
|
490
|
+
let isExists: Bool = try UtilsJson.isTableExists(
|
|
491
|
+
mDB: self, tableName: "sync_table")
|
|
492
|
+
if !isExists {
|
|
493
|
+
throw DatabaseError.createSyncDate(message: "No sync_table available")
|
|
494
|
+
}
|
|
481
495
|
let dateFormatter = DateFormatter()
|
|
482
496
|
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
|
|
483
497
|
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
|
|
@@ -494,6 +508,8 @@ class Database {
|
|
|
494
508
|
} else {
|
|
495
509
|
throw DatabaseError.createSyncDate(message: "wrong syncDate")
|
|
496
510
|
}
|
|
511
|
+
} catch UtilsJsonError.tableNotExists(let message) {
|
|
512
|
+
throw DatabaseError.createSyncDate(message: message)
|
|
497
513
|
} catch DatabaseError.runSQL(let message) {
|
|
498
514
|
throw DatabaseError.createSyncDate(message: message)
|
|
499
515
|
}
|
|
@@ -505,7 +521,14 @@ class Database {
|
|
|
505
521
|
func getSyncDate( ) throws -> Int64 {
|
|
506
522
|
var syncDate: Int64 = 0
|
|
507
523
|
do {
|
|
524
|
+
let isExists: Bool = try UtilsJson.isTableExists(
|
|
525
|
+
mDB: self, tableName: "sync_table")
|
|
526
|
+
if !isExists {
|
|
527
|
+
throw DatabaseError.getSyncDate(message: "No sync_table available")
|
|
528
|
+
}
|
|
508
529
|
syncDate = try ExportToJson.getSyncDate(mDB: self)
|
|
530
|
+
} catch UtilsJsonError.tableNotExists(let message) {
|
|
531
|
+
throw DatabaseError.getSyncDate(message: message)
|
|
509
532
|
} catch ExportToJsonError.getSyncDate(let message) {
|
|
510
533
|
throw DatabaseError.getSyncDate(message: message)
|
|
511
534
|
}
|
|
@@ -88,6 +88,12 @@ class ExportToJson {
|
|
|
88
88
|
let resTables = try UtilsSQLCipher.querySQL(
|
|
89
89
|
mDB: mDB, sql: query, values: [])
|
|
90
90
|
if resTables.count > 0 {
|
|
91
|
+
let isExists: Bool = try UtilsJson.isTableExists(
|
|
92
|
+
mDB: mDB, tableName: "sync_table")
|
|
93
|
+
if !isExists && expMode == "partial" {
|
|
94
|
+
throw ExportToJsonError.createExportObject(message: "No sync_table available")
|
|
95
|
+
}
|
|
96
|
+
|
|
91
97
|
switch expMode {
|
|
92
98
|
case "partial" :
|
|
93
99
|
tables = try ExportToJson
|
|
@@ -102,6 +108,8 @@ class ExportToJson {
|
|
|
102
108
|
message: "expMode \(expMode) not defined")
|
|
103
109
|
}
|
|
104
110
|
}
|
|
111
|
+
} catch UtilsJsonError.tableNotExists(let message) {
|
|
112
|
+
throw ExportToJsonError.createExportObject(message: message)
|
|
105
113
|
} catch UtilsSQLCipherError.querySQL(let message) {
|
|
106
114
|
throw ExportToJsonError.createExportObject(
|
|
107
115
|
message: "Error get table's names failed : \(message)")
|
|
@@ -194,12 +194,16 @@ class ImportFromJson {
|
|
|
194
194
|
-> [String] {
|
|
195
195
|
var statements: [String] = []
|
|
196
196
|
var stmt: String
|
|
197
|
+
var isLastModified: Bool = false
|
|
197
198
|
stmt = "CREATE TABLE IF NOT EXISTS "
|
|
198
199
|
stmt.append(tableName)
|
|
199
200
|
stmt.append(" (")
|
|
200
201
|
for jpos in 0..<mSchema.count {
|
|
201
202
|
if let jSchColumn = mSchema[jpos].column {
|
|
202
203
|
if jSchColumn.count > 0 {
|
|
204
|
+
if jSchColumn == "last_modified" {
|
|
205
|
+
isLastModified = true
|
|
206
|
+
}
|
|
203
207
|
stmt.append(jSchColumn)
|
|
204
208
|
}
|
|
205
209
|
}
|
|
@@ -221,20 +225,22 @@ class ImportFromJson {
|
|
|
221
225
|
}
|
|
222
226
|
stmt.append(");")
|
|
223
227
|
statements.append(stmt)
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
228
|
+
if isLastModified {
|
|
229
|
+
// create trigger last_modified associated with the table
|
|
230
|
+
let triggerName: String = tableName + "_trigger_last_modified"
|
|
231
|
+
stmt = "CREATE TRIGGER IF NOT EXISTS "
|
|
232
|
+
stmt.append(triggerName)
|
|
233
|
+
stmt.append(" AFTER UPDATE ON ")
|
|
234
|
+
stmt.append(tableName)
|
|
235
|
+
stmt.append(" FOR EACH ROW ")
|
|
236
|
+
stmt.append("WHEN NEW.last_modified <= OLD.last_modified ")
|
|
237
|
+
stmt.append("BEGIN UPDATE ")
|
|
238
|
+
stmt.append(tableName)
|
|
239
|
+
stmt.append(" SET last_modified = (strftime('%s','now')) ")
|
|
240
|
+
stmt.append("WHERE id=OLD.id; ")
|
|
241
|
+
stmt.append("END;")
|
|
242
|
+
statements.append(stmt)
|
|
243
|
+
}
|
|
238
244
|
return statements
|
|
239
245
|
}
|
|
240
246
|
|
|
@@ -17,6 +17,7 @@ enum UtilsJsonError: Error {
|
|
|
17
17
|
case validateIndexes(message: String)
|
|
18
18
|
case validateTriggers(message: String)
|
|
19
19
|
case validateViews(message: String)
|
|
20
|
+
case isLastModified(message: String)
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
// swiftlint:disable type_body_length
|
|
@@ -46,6 +47,33 @@ class UtilsJson {
|
|
|
46
47
|
return ret
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
// MARK: - ImportFromJson - IsLastModified
|
|
51
|
+
|
|
52
|
+
class func isLastModified(mDB: Database) throws -> Bool {
|
|
53
|
+
var msg: String = "Error LastModified: "
|
|
54
|
+
if !mDB.isDBOpen() {
|
|
55
|
+
msg.append("Database not opened")
|
|
56
|
+
throw UtilsJsonError.isLastModified(message: msg)
|
|
57
|
+
}
|
|
58
|
+
var ret: Bool = false
|
|
59
|
+
do {
|
|
60
|
+
let tableList: [String] = try UtilsDrop.getTablesNames(mDB: mDB)
|
|
61
|
+
for table in tableList {
|
|
62
|
+
let namesTypes: JsonNamesTypes = try getTableColumnNamesTypes(mDB: mDB,
|
|
63
|
+
tableName: table)
|
|
64
|
+
if namesTypes.names.contains("last_modified") {
|
|
65
|
+
ret = true
|
|
66
|
+
break
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch UtilsJsonError.getTableColumnNamesTypes(let message) {
|
|
70
|
+
throw UtilsJsonError.isLastModified(message: message)
|
|
71
|
+
} catch UtilsDropError.getTablesNamesFailed(let message) {
|
|
72
|
+
throw UtilsJsonError.isLastModified(message: message)
|
|
73
|
+
}
|
|
74
|
+
return ret
|
|
75
|
+
}
|
|
76
|
+
|
|
49
77
|
// MARK: - ImportFromJson - IsViewExists
|
|
50
78
|
|
|
51
79
|
class func isViewExists(mDB: Database, viewName: String)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/sqlite",
|
|
3
|
-
"version": "3.4.1-
|
|
3
|
+
"version": "3.4.1-4",
|
|
4
4
|
"description": "Community plugin for native & electron SQLite databases",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -91,5 +91,8 @@
|
|
|
91
91
|
"electron": {
|
|
92
92
|
"src": "electron"
|
|
93
93
|
}
|
|
94
|
+
},
|
|
95
|
+
"dependencies": {
|
|
96
|
+
"jeep-sqlite": "^1.3.7"
|
|
94
97
|
}
|
|
95
98
|
}
|