Skip to content

Commit

Permalink
last Capacitor 5 release
Browse files Browse the repository at this point in the history
  • Loading branch information
jepiqueau committed Jun 9, 2024
1 parent 7e6a6dd commit 335cb8c
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 56 deletions.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@
<p align="center"><strong><code>@capacitor-community/sqlite</code></strong></p>
<br>
<p align="center" style="font-size:50px;color:red"><strong>CAPACITOR 5</strong></p><br>
<br>
<!-- Note from the Owner - Start -->
<p align="center" style="font-size:50px;color:red"><strong>Note from the Owner</strong></p>
<!-- Note from the Owner - End -->
<br>
<!-- Message below Note from the Owner - Start -->
<p align="left" style="font-size:47px">Start --></p>
<br>
<p align="left">
I have been dedicated to developing and maintaining this plugin for many years since the inception of Ionic Capacitor. Now, at 73+ years old, and with my MacBook Pro becoming obsolete for running Capacitor 6 for iOS, I have made the decision to cease maintenance of the plugin. If anyone wishes to take ownership of this plugin, they are welcome to do so.
</p>
<br>
<p align="left">
It has been a great honor to be part of this development journey alongside the developer community. I am grateful to see many of you following me on this path and incorporating the plugin into your applications. Your comments and suggestions have motivated me to continuously improve it.
</p>
<br>
<p align="left">
I have made this decision due to several family-related troubles that require my full attention and time. Therefore, I will not be stepping back. Thank you to all of you for your support.
</p>
<br>
<p align="left" style="font-size:47px">End <--</p>
<!-- Message below Note from the Owner - End -->
<br>

<p align="center">
Capacitor community plugin for Native and Electron SQLite Databases.
Expand All @@ -18,7 +41,7 @@
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/dw/@capacitor-community/sqlite?style=flat-square" /></a>
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/v/@capacitor-community/sqlite?style=flat-square" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-44-orange?style=flat-square" /></a>
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-45-orange?style=flat-square" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
</p>

Expand Down Expand Up @@ -416,6 +439,8 @@ lasher23"><img src="https://avatars.githubusercontent.com/u/24244618?v=4" width=
mirsella"><img src="https://avatars.githubusercontent.com/u/45905567?v=4" width="50" height="50" /></a>
<a href="https://github.com/SaintPepsi" title="
SaintPepsi"><img src="https://avatars.githubusercontent.com/u/16056759?v=4" width="50" height="50" /></a>
<a href="https://github.com/l1ndch" title="
l1ndch"><img src="https://avatars.githubusercontent.com/u/170952278?v=4" width="50" height="50" /></a>
</p>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ private ArrayList<JsonColumn> getSchema(String sqlStmt) throws Exception {
String sc = s.replaceAll("\n", "").trim();
String[] row = sc.trim().split(" ", 2);
JsonColumn jsonRow = new JsonColumn();
String uppercasedValue = row[0].toUpperCase(); // Define uppercasedValue
int oPar;
int cPar;
switch (row[0].toUpperCase()) {
Expand All @@ -356,11 +357,12 @@ private ArrayList<JsonColumn> getSchema(String sqlStmt) throws Exception {
row[1] = sc.substring(cPar + 2);
jsonRow.setForeignkey(row[0]);
}
case "PRIMARY" -> {
case "PRIMARY", "UNIQUE" -> {
String prefix = uppercasedValue.equals("PRIMARY") ? "CPK_" : "CUN_";
oPar = sc.indexOf("(");
cPar = sc.indexOf(")");
String pk = sc.substring(oPar + 1, cPar);
row[0] = "CPK_" + pk.replaceAll("§", "_");
row[0] = prefix + pk.replaceAll("§", "_");
row[0] = row[0].replaceAll("_ ", "_");
row[1] = sc.substring(0, cPar + 1);
jsonRow.setConstraint(row[0]);
Expand Down
68 changes: 40 additions & 28 deletions electron/src/electron-utils/ImportExportJson/exportToJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,35 +329,47 @@ export class ExportToJson {
row[1] = scht.substring(scht.indexOf(' ') + 1);

const jsonRow: JsonColumn = {} as JsonColumn;
if (row[0].toUpperCase() === 'FOREIGN') {
const oPar: number = scht.indexOf('(');
const cPar: number = scht.indexOf(')');
const fk = scht.substring(oPar + 1, cPar);
const fknames: string[] = fk.split('§');
row[0] = fknames.join(',');
row[0] = row[0].replace(/, /g, ',');
row[1] = scht.substring(cPar + 2);
jsonRow['foreignkey'] = row[0];
} else if (row[0].toUpperCase() === 'PRIMARY') {
const oPar: number = scht.indexOf('(');
const cPar: number = scht.indexOf(')');
const pk: string = scht.substring(oPar + 1, cPar);
const pknames: string[] = pk.split('§');
row[0] = 'CPK_' + pknames.join('_');
row[0] = row[0].replace(/_ /g, '_');
row[1] = scht;
jsonRow['constraint'] = row[0];
} else if (row[0].toUpperCase() === 'CONSTRAINT') {
const tRow: string[] = [];
const row1t: string = row[1].trim();
tRow[0] = row1t.substring(0, row1t.indexOf(' '));
tRow[1] = row1t.substring(row1t.indexOf(' ') + 1);
row[0] = tRow[0];
jsonRow['constraint'] = row[0];
row[1] = tRow[1];
} else {
jsonRow['column'] = row[0];
switch (row[0].toUpperCase()) {
case 'FOREIGN': {
const oPar: number = scht.indexOf('(');
const cPar: number = scht.indexOf(')');
const fk = scht.substring(oPar + 1, cPar);
const fknames: string[] = fk.split('§');
row[0] = fknames.join(',');
row[0] = row[0].replace(/, /g, ',');
row[1] = scht.substring(cPar + 2);
jsonRow['foreignkey'] = row[0];
break;
}
case 'PRIMARY':
case 'UNIQUE': {
const prefix = row[0].toUpperCase() === 'PRIMARY' ? 'CPK_' : 'CUN_';
const oPar: number = scht.indexOf('(');
const cPar: number = scht.indexOf(')');
const pk: string = scht.substring(oPar + 1, cPar);
const pknames: string[] = pk.split('§');
row[0] = prefix + pknames.join('_');
row[0] = row[0].replace(/_ /g, '_');
row[1] = scht;
jsonRow['constraint'] = row[0];
break;
}
case 'CONSTRAINT': {
const tRow: string[] = [];
const row1t: string = row[1].trim();
tRow[0] = row1t.substring(0, row1t.indexOf(' '));
tRow[1] = row1t.substring(row1t.indexOf(' ') + 1);
row[0] = tRow[0];
jsonRow['constraint'] = row[0];
row[1] = tRow[1];
break;
}
default: {
jsonRow['column'] = row[0];
break;
}
}

jsonRow['value'] = row[1].replace(/§/g, ',');
schema.push(jsonRow);
}
Expand Down
8 changes: 5 additions & 3 deletions electron/src/electron-utils/utilsSQLite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,10 @@ export class UtilsSQLite {
try {
initChanges = this.dbChanges(mDB);
let sqlStmt = sql;

// modify sql to sql92 compatible
sqlStmt = this.statementsToSQL92(mDB, sql, fromJson, isSQL92);

this.execDB(mDB, sqlStmt);
changes = this.dbChanges(mDB) - initChanges;
lastId = this.getLastId(mDB);
Expand Down Expand Up @@ -523,13 +524,14 @@ export class UtilsSQLite {
let mVal: any[] = [];
if (mValues.length > 0) {
mVal = this.replaceUndefinedByNull(mValues);
} else {

}/* else {
const findVals = sqlStmt.match(/\?/gi);
const nbValues = findVals ? findVals.length : 0;
for (let i = 0; i < nbValues; i++) {
mVal.push(null);
}
}
}*/
const ret: RunResults = this.runExec(mDB, sqlStmt, mVal, returnMode);
if (ret.values != null) {
result.values = ret.values;
Expand Down
10 changes: 6 additions & 4 deletions ios/Plugin/ImportExportJson/ExportToJson.swift
Original file line number Diff line number Diff line change
Expand Up @@ -867,26 +867,28 @@ class ExportToJson {
with: ",")
.replacingOccurrences(of: ", ",
with: ",")
case "PRIMARY":
case "PRIMARY", "UNIQUE":
let prefix = (String(row[0]).uppercased() == "PRIMARY") ? "CPK_" : "CUN_"

guard let oPar = rstr.firstIndex(of: "(")
else {
var msg: String = "Create Schema "
msg.append("PRIMARY KEY no '('")
msg.append("PRIMARY/UNIQUE KEY no '('")
throw ExportToJsonError
.createSchema(message: msg)
}
guard let cPar = rstr.firstIndex(of: ")")
else {
var msg: String = "Create Schema "
msg.append("PRIMARY KEY no ')'")
msg.append("PRIMARY/UNIQUE KEY no ')'")
throw ExportToJsonError
.createSchema(message: msg)
}
row[0] = rstr[rstr.index(
after: oPar)..<cPar]
row[1] = rstr[rstr.index(rstr.startIndex,
offsetBy: 0)..<rstr.endIndex]
columns["constraint"] = "CPK_" + String(row[0])
columns["constraint"] = prefix + String(row[0])
.replacingOccurrences(of: "§",
with: "_")
.replacingOccurrences(of: "_ ",
Expand Down
16 changes: 7 additions & 9 deletions ios/Plugin/Utils/UtilsDownloadFromHTTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,14 @@ class UtilsDownloadFromHTTP {
}

class func extractDBFiles(from zipFile: URL, completion: @escaping ([URL], Error?) -> Void) {
DispatchQueue.global().async(execute: {
DispatchQueue.global().async {
var dbFiles: [URL] = []

do {
let destinationURL = zipFile.deletingLastPathComponent()

guard let archive = Archive(url: zipFile, accessMode: .read) else {
let msg = "Failed in reading Archive"
completion([], UtilsDownloadError.invalidArchive(message: msg))
return
}
// Use the throwing initializer
let archive = try Archive(url: zipFile, accessMode: .read)

for entry in archive where entry.type == .file {
let fileURL = destinationURL.appendingPathComponent(entry.path)
Expand All @@ -179,14 +176,15 @@ class UtilsDownloadFromHTTP {
dbFiles.append(fileURL)
}
}

// Delete the zip file
try FileManager.default.removeItem(at: zipFile)

completion(dbFiles, nil)
} catch {
completion([], error)
let msg = "Failed in reading Archive: \(error.localizedDescription)"
completion([], UtilsDownloadError.invalidArchive(message: msg))
}
})

}
}
}
13 changes: 5 additions & 8 deletions ios/Plugin/Utils/UtilsFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,13 @@ class UtilsFile {

}

class func unzipToDatabase(fromURL: URL, databaseLocation: String, zip: String,
overwrite: Bool) throws {
class func unzipToDatabase(fromURL: URL, databaseLocation: String, zip: String, overwrite: Bool) throws {
do {
let zipAsset: URL = fromURL.appendingPathComponent(zip)
guard let archive = Archive(url: zipAsset, accessMode: .read) else {
let msg = "Error: Read Archive: \(zipAsset) failed"
print("\(msg)")
throw UtilsFileError.unzipToDatabaseFailed(message: msg)
}

// Use the throwing initializer
let archive = try Archive(url: zipAsset, accessMode: .read)

let uDb: URL = try getFolderURL(folderPath: databaseLocation)
for entry in archive {
let dbEntry = setPathSuffix(sDb: entry.path)
Expand All @@ -442,7 +440,6 @@ class UtilsFile {
}
_ = try archive.extract(entry, to: zipCopy)
}

} catch {
let msg = "Error: Extracting \(entry.path) from archive failed \(error.localizedDescription)"
print("\(msg)")
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@
}
},
"dependencies": {
"jeep-sqlite": "^2.7.0"
"jeep-sqlite": "^2.7.2"
}
}

0 comments on commit 335cb8c

Please sign in to comment.