@capacitor-community/sqlite
Advanced tools
Comparing version 2.9.9 to 2.9.10
@@ -0,1 +1,19 @@ | ||
# 2.9.10 (2021-02-14) REFACTOR | ||
### Added Features | ||
- isConnection method | ||
- isDatabase method | ||
- getDatabaseList method | ||
- isTable method | ||
- addSQLiteSuffix method | ||
- deleteOldDatabases method | ||
- MigratingCordovaDatabases.md | ||
### Bug Fixes | ||
- Fix Copy db from storage issue#77 | ||
- Fix Is there a way to connect to a db file, that not has the prefix SQLite.db issue#79 | ||
- Fix More precise error message on failing statements issue#82 | ||
## 2.9.9 (2021-02-01) REFACTOR | ||
@@ -2,0 +20,0 @@ |
@@ -75,3 +75,3 @@ declare module '@capacitor/core' { | ||
/** | ||
* Check is a SQLite database exists | ||
* Check if a SQLite database exists with opened connection | ||
* @param options: capSQLiteOptions | ||
@@ -83,2 +83,16 @@ * @returns Promise<capSQLiteResult> | ||
/** | ||
* Check if a SQLite database exists without connection | ||
* @param options: capSQLiteOptions | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 | ||
*/ | ||
isDatabase(options: capSQLiteOptions): Promise<capSQLiteResult>; | ||
/** | ||
* Check if a table exists in a SQLite database | ||
* @param options: capSQLiteTableOptions | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 | ||
*/ | ||
isTableExists(options: capSQLiteTableOptions): Promise<capSQLiteResult>; | ||
/** | ||
* Delete a SQLite database | ||
@@ -146,2 +160,22 @@ * @param options: capSQLiteOptions | ||
copyFromAssets(): Promise<capSQLiteResult>; | ||
/** | ||
* Get the database list | ||
* @returns Promise<capSQLiteValues> | ||
* @since 2.9.10 refactor | ||
*/ | ||
getDatabaseList(): Promise<capSQLiteValues>; | ||
/** | ||
* Add SQLIte Suffix to existing databases | ||
* @param options: capSQLitePathOptions | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 refactor | ||
*/ | ||
addSQLiteSuffix(options: capSQLitePathOptions): Promise<capSQLiteResult>; | ||
/** | ||
* Delete Old Cordova databases | ||
* @param options: capSQLitePathOptions | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 refactor | ||
*/ | ||
deleteOldDatabases(options: capSQLitePathOptions): Promise<capSQLiteResult>; | ||
} | ||
@@ -278,2 +312,18 @@ export interface capEchoOptions { | ||
} | ||
export interface capSQLitePathOptions { | ||
/** | ||
* The folder path of existing databases | ||
*/ | ||
folderPath?: string; | ||
} | ||
export interface capSQLiteTableOptions { | ||
/** | ||
* The database name | ||
*/ | ||
database?: string; | ||
/** | ||
* The table name | ||
*/ | ||
table?: string; | ||
} | ||
export interface capEchoResult { | ||
@@ -484,2 +534,9 @@ /** | ||
/** | ||
* Check if a connection exists | ||
* @param database | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 refactor | ||
*/ | ||
isConnection(database: string): Promise<capSQLiteResult>; | ||
/** | ||
* Retrieve an existing database connection | ||
@@ -530,2 +587,29 @@ * @param database | ||
copyFromAssets(): Promise<capSQLiteResult>; | ||
/** | ||
* Check if a database exists | ||
* @param database | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 refactor | ||
*/ | ||
isDatabase(database: string): Promise<capSQLiteResult>; | ||
/** | ||
* Get the database list | ||
* @returns Promise<capSQLiteValues> | ||
* @since 2.9.10 refactor | ||
*/ | ||
getDatabaseList(): Promise<capSQLiteValues>; | ||
/** | ||
* Add SQLIte Suffix to existing databases | ||
* @param folderPath | ||
* @returns Promise<capSQLiteValues> | ||
* @since 2.9.10 refactor | ||
*/ | ||
addSQLiteSuffix(folderPath?: string): Promise<capSQLiteResult>; | ||
/** | ||
* Delete Old Cordova databases | ||
* @param folderPath | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 refactor | ||
*/ | ||
deleteOldDatabases(folderPath?: string): Promise<capSQLiteResult>; | ||
} | ||
@@ -543,2 +627,3 @@ /** | ||
closeConnection(database: string): Promise<capSQLiteResult>; | ||
isConnection(database: string): Promise<capSQLiteResult>; | ||
retrieveConnection(database: string): Promise<SQLiteDBConnection | null | undefined>; | ||
@@ -550,2 +635,6 @@ retrieveAllConnections(): Promise<Map<string, SQLiteDBConnection>>; | ||
copyFromAssets(): Promise<capSQLiteResult>; | ||
isDatabase(database: string): Promise<capSQLiteResult>; | ||
getDatabaseList(): Promise<capSQLiteValues>; | ||
addSQLiteSuffix(folderPath?: string): Promise<capSQLiteResult>; | ||
deleteOldDatabases(folderPath?: string): Promise<capSQLiteResult>; | ||
} | ||
@@ -611,2 +700,8 @@ /** | ||
/** | ||
* Check if a SQLite DB Connection exists | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 refactor | ||
*/ | ||
isTable(table: string): Promise<capSQLiteResult>; | ||
/** | ||
* Delete a SQLite DB Connection | ||
@@ -659,2 +754,3 @@ * @returns Promise<capSQLiteResult> | ||
isExists(): Promise<capSQLiteResult>; | ||
isTable(table: string): Promise<capSQLiteResult>; | ||
delete(): Promise<capSQLiteResult>; | ||
@@ -661,0 +757,0 @@ createSyncTable(): Promise<capSQLiteChanges>; |
@@ -65,2 +65,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
isConnection(database) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let res = {}; | ||
res.result = this._connectionDict.has(database); | ||
return res; | ||
}); | ||
} | ||
retrieveConnection(database) { | ||
@@ -110,2 +117,24 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
isDatabase(database) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.sqlite.isDatabase({ database: database }); | ||
}); | ||
} | ||
getDatabaseList() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.sqlite.getDatabaseList(); | ||
}); | ||
} | ||
addSQLiteSuffix(folderPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = folderPath ? folderPath : 'default'; | ||
return yield this.sqlite.addSQLiteSuffix({ folderPath: path }); | ||
}); | ||
} | ||
deleteOldDatabases(folderPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = folderPath ? folderPath : 'default'; | ||
return yield this.sqlite.deleteOldDatabases({ folderPath: path }); | ||
}); | ||
} | ||
} | ||
@@ -202,2 +231,11 @@ /** | ||
} | ||
isTable(table) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield this.sqlite.isTableExists({ | ||
database: this.dbName, | ||
table: table, | ||
}); | ||
return res; | ||
}); | ||
} | ||
delete() { | ||
@@ -204,0 +242,0 @@ return __awaiter(this, void 0, void 0, function* () { |
import { WebPlugin } from '@capacitor/core'; | ||
import { CapacitorSQLitePlugin, capEchoOptions, capSQLiteOptions, capSQLiteExecuteOptions, capSQLiteSetOptions, capSQLiteRunOptions, capSQLiteQueryOptions, capSQLiteImportOptions, capSQLiteExportOptions, capSQLiteSyncDateOptions, capEchoResult, capSQLiteResult, capSQLiteChanges, capSQLiteValues, capSQLiteJson, capSQLiteUpgradeOptions, capSQLiteSyncDate } from './definitions'; | ||
import { CapacitorSQLitePlugin, capEchoOptions, capSQLiteOptions, capSQLiteExecuteOptions, capSQLiteSetOptions, capSQLiteRunOptions, capSQLiteQueryOptions, capSQLiteImportOptions, capSQLiteExportOptions, capSQLiteSyncDateOptions, capSQLiteUpgradeOptions, capSQLiteTableOptions, capSQLitePathOptions, capEchoResult, capSQLiteResult, capSQLiteChanges, capSQLiteValues, capSQLiteJson, capSQLiteSyncDate } from './definitions'; | ||
export declare class CapacitorSQLiteWeb extends WebPlugin implements CapacitorSQLitePlugin { | ||
@@ -15,2 +15,4 @@ constructor(); | ||
isDBExists(options: capSQLiteOptions): Promise<capSQLiteResult>; | ||
isDatabase(options: capSQLiteOptions): Promise<capSQLiteResult>; | ||
isTableExists(options: capSQLiteTableOptions): Promise<capSQLiteResult>; | ||
deleteDatabase(options: capSQLiteOptions): Promise<capSQLiteResult>; | ||
@@ -25,4 +27,7 @@ isJsonValid(options: capSQLiteImportOptions): Promise<capSQLiteResult>; | ||
copyFromAssets(): Promise<capSQLiteResult>; | ||
getDatabaseList(): Promise<capSQLiteValues>; | ||
addSQLiteSuffix(options: capSQLitePathOptions): Promise<capSQLiteResult>; | ||
deleteOldDatabases(options: capSQLitePathOptions): Promise<capSQLiteResult>; | ||
} | ||
declare const CapacitorSQLite: CapacitorSQLiteWeb; | ||
export { CapacitorSQLite }; |
@@ -11,3 +11,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { WebPlugin } from '@capacitor/core'; | ||
//1234567890123456789012345678901234567890123456789012345678901234567890 | ||
export class CapacitorSQLiteWeb extends WebPlugin { | ||
@@ -107,2 +106,20 @@ constructor() { | ||
} | ||
isDatabase(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
console.log('in Web isDatabase', options); | ||
return Promise.resolve({ | ||
result: false, | ||
message: `Not implemented on Web Platform`, | ||
}); | ||
}); | ||
} | ||
isTableExists(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
console.log('in Web isTableExists', options); | ||
return Promise.resolve({ | ||
result: false, | ||
message: `Not implemented on Web Platform`, | ||
}); | ||
}); | ||
} | ||
deleteDatabase(options) { | ||
@@ -187,2 +204,28 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
getDatabaseList() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return Promise.resolve({ | ||
values: [], | ||
message: `Not implemented on Web Platform`, | ||
}); | ||
}); | ||
} | ||
addSQLiteSuffix(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
console.log('addSQLiteSuffix', options); | ||
return Promise.resolve({ | ||
result: false, | ||
message: `Not implemented on Web Platform`, | ||
}); | ||
}); | ||
} | ||
deleteOldDatabases(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
console.log('deleteOldDatabases', options); | ||
return Promise.resolve({ | ||
result: false, | ||
message: `Not implemented on Web Platform`, | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -189,0 +232,0 @@ const CapacitorSQLite = new CapacitorSQLiteWeb(); |
@@ -68,2 +68,9 @@ var capacitorPlugin = (function (exports, core) { | ||
} | ||
isConnection(database) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let res = {}; | ||
res.result = this._connectionDict.has(database); | ||
return res; | ||
}); | ||
} | ||
retrieveConnection(database) { | ||
@@ -113,2 +120,24 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
isDatabase(database) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.sqlite.isDatabase({ database: database }); | ||
}); | ||
} | ||
getDatabaseList() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.sqlite.getDatabaseList(); | ||
}); | ||
} | ||
addSQLiteSuffix(folderPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = folderPath ? folderPath : 'default'; | ||
return yield this.sqlite.addSQLiteSuffix({ folderPath: path }); | ||
}); | ||
} | ||
deleteOldDatabases(folderPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = folderPath ? folderPath : 'default'; | ||
return yield this.sqlite.deleteOldDatabases({ folderPath: path }); | ||
}); | ||
} | ||
} | ||
@@ -205,2 +234,11 @@ /** | ||
} | ||
isTable(table) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield this.sqlite.isTableExists({ | ||
database: this.dbName, | ||
table: table, | ||
}); | ||
return res; | ||
}); | ||
} | ||
delete() { | ||
@@ -259,3 +297,2 @@ return __awaiter(this, void 0, void 0, function* () { | ||
}; | ||
//1234567890123456789012345678901234567890123456789012345678901234567890 | ||
class CapacitorSQLiteWeb extends core.WebPlugin { | ||
@@ -355,2 +392,20 @@ constructor() { | ||
} | ||
isDatabase(options) { | ||
return __awaiter$1(this, void 0, void 0, function* () { | ||
console.log('in Web isDatabase', options); | ||
return Promise.resolve({ | ||
result: false, | ||
message: `Not implemented on Web Platform`, | ||
}); | ||
}); | ||
} | ||
isTableExists(options) { | ||
return __awaiter$1(this, void 0, void 0, function* () { | ||
console.log('in Web isTableExists', options); | ||
return Promise.resolve({ | ||
result: false, | ||
message: `Not implemented on Web Platform`, | ||
}); | ||
}); | ||
} | ||
deleteDatabase(options) { | ||
@@ -435,2 +490,28 @@ return __awaiter$1(this, void 0, void 0, function* () { | ||
} | ||
getDatabaseList() { | ||
return __awaiter$1(this, void 0, void 0, function* () { | ||
return Promise.resolve({ | ||
values: [], | ||
message: `Not implemented on Web Platform`, | ||
}); | ||
}); | ||
} | ||
addSQLiteSuffix(options) { | ||
return __awaiter$1(this, void 0, void 0, function* () { | ||
console.log('addSQLiteSuffix', options); | ||
return Promise.resolve({ | ||
result: false, | ||
message: `Not implemented on Web Platform`, | ||
}); | ||
}); | ||
} | ||
deleteOldDatabases(options) { | ||
return __awaiter$1(this, void 0, void 0, function* () { | ||
console.log('deleteOldDatabases', options); | ||
return Promise.resolve({ | ||
result: false, | ||
message: `Not implemented on Web Platform`, | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -437,0 +518,0 @@ const CapacitorSQLite = new CapacitorSQLiteWeb(); |
@@ -47,2 +47,3 @@ import { capSQLiteVersionUpgrade, JsonSQLite } from '../definitions'; | ||
deleteDB(dbName: string): Promise<void>; | ||
isTableExists(tableName: string): Promise<any>; | ||
/** | ||
@@ -49,0 +50,0 @@ * CreateSyncTable |
@@ -163,2 +163,22 @@ import { __awaiter } from "tslib"; | ||
} | ||
isTableExists(tableName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const isOpen = this._isDBOpen; | ||
try { | ||
const retB = yield this._uJson.isTableExists(this._mDB, isOpen, tableName); | ||
if (retB) { | ||
return { result: true }; | ||
} | ||
else { | ||
return { | ||
result: false, | ||
message: `IsTableExists: table ${tableName} does not exist`, | ||
}; | ||
} | ||
} | ||
catch (err) { | ||
return { result: false, message: `IsTableExists: ${err.message}` }; | ||
} | ||
}); | ||
} | ||
/** | ||
@@ -165,0 +185,0 @@ * CreateSyncTable |
@@ -28,2 +28,12 @@ export declare class UtilsFile { | ||
/** | ||
* GetCustomerPath | ||
* get the customer path | ||
*/ | ||
getCustomerPath(custPath: string): string; | ||
/** | ||
* GetCustomerFilePath | ||
* get the customer file path | ||
*/ | ||
getCustomerFilePath(custPath: string, file: string): string; | ||
/** | ||
* GetDatabasesPath | ||
@@ -69,2 +79,3 @@ * get the database folder path | ||
copyFilePath(filePath: string, toFilePath: string): Promise<void>; | ||
copyFile(fromPath: string, fromFile: string, toPath: string, toFile: string): Promise<void>; | ||
/** | ||
@@ -71,0 +82,0 @@ * DeleteFileName |
@@ -63,2 +63,16 @@ import { __awaiter } from "tslib"; | ||
/** | ||
* GetCustomerPath | ||
* get the customer path | ||
*/ | ||
getCustomerPath(custPath) { | ||
return this.Path.join(this.HomeDir, custPath); | ||
} | ||
/** | ||
* GetCustomerFilePath | ||
* get the customer file path | ||
*/ | ||
getCustomerFilePath(custPath, file) { | ||
return this.Path.join(custPath, file); | ||
} | ||
/** | ||
* GetDatabasesPath | ||
@@ -210,2 +224,15 @@ * get the database folder path | ||
} | ||
copyFile(fromPath, fromFile, toPath, toFile) { | ||
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
const fPath = this.Path.join(fromPath, fromFile); | ||
const tPath = this.Path.join(toPath, toFile); | ||
try { | ||
this.NodeFs.copyFileSync(fPath, tPath); | ||
resolve(); | ||
} | ||
catch (err) { | ||
reject(new Error(`CopyFile: ${err.message}`)); | ||
} | ||
})); | ||
} | ||
/** | ||
@@ -212,0 +239,0 @@ * DeleteFileName |
import { WebPlugin } from '@capacitor/core'; | ||
import { CapacitorSQLitePlugin, capConnectionOptions, capEchoOptions, capEchoResult, capSQLiteChanges, capSQLiteExecuteOptions, capSQLiteExportOptions, capSQLiteImportOptions, capSQLiteJson, capSQLiteOptions, capSQLiteQueryOptions, capSQLiteResult, capSQLiteRunOptions, capSQLiteSetOptions, capSQLiteSyncDateOptions, capSQLiteUpgradeOptions, capSQLiteValues, capSQLiteSyncDate } from './definitions'; | ||
import { CapacitorSQLitePlugin, capConnectionOptions, capEchoOptions, capEchoResult, capSQLiteChanges, capSQLiteExecuteOptions, capSQLiteExportOptions, capSQLiteImportOptions, capSQLiteJson, capSQLiteOptions, capSQLiteQueryOptions, capSQLiteResult, capSQLiteRunOptions, capSQLiteSetOptions, capSQLiteSyncDateOptions, capSQLiteUpgradeOptions, capSQLiteValues, capSQLiteSyncDate, capSQLiteTableOptions, capSQLitePathOptions } from './definitions'; | ||
export declare class CapacitorSQLiteElectronWeb extends WebPlugin implements CapacitorSQLitePlugin { | ||
@@ -8,2 +8,3 @@ RemoteRef: any; | ||
private _uJson; | ||
private _uMigrate; | ||
private _osType; | ||
@@ -22,2 +23,7 @@ private _versionUpgrades; | ||
isDBExists(options: capSQLiteOptions): Promise<capSQLiteResult>; | ||
isDatabase(options: capSQLiteOptions): Promise<capSQLiteResult>; | ||
isTableExists(options: capSQLiteTableOptions): Promise<capSQLiteResult>; | ||
getDatabaseList(): Promise<capSQLiteValues>; | ||
addSQLiteSuffix(options: capSQLitePathOptions): Promise<capSQLiteResult>; | ||
deleteOldDatabases(options: capSQLitePathOptions): Promise<capSQLiteResult>; | ||
deleteDatabase(options: capSQLiteOptions): Promise<capSQLiteResult>; | ||
@@ -24,0 +30,0 @@ isJsonValid(options: capSQLiteImportOptions): Promise<capSQLiteResult>; |
@@ -6,3 +6,3 @@ import { __awaiter } from "tslib"; | ||
import { UtilsJson } from './electron-utils/ImportExportJson/utilsJson'; | ||
//1234567890123456789012345678901234567890123456789012345678901234567890 | ||
import { UtilsMigrate } from './electron-utils/utilsMigrate'; | ||
const { remote } = require('electron'); | ||
@@ -19,2 +19,3 @@ export class CapacitorSQLiteElectronWeb extends WebPlugin { | ||
this._uJson = new UtilsJson(); | ||
this._uMigrate = new UtilsMigrate(); | ||
this._versionUpgrades = {}; | ||
@@ -371,2 +372,106 @@ console.log('CapacitorSQLite Electron'); | ||
} | ||
isDatabase(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let keys = Object.keys(options); | ||
if (!keys.includes('database')) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: 'Must provide a database name', | ||
}); | ||
} | ||
const dbName = options.database; | ||
const isExists = this._uFile.isFileExists(dbName + 'SQLite.db'); | ||
return Promise.resolve({ | ||
result: isExists, | ||
}); | ||
}); | ||
} | ||
isTableExists(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let keys = Object.keys(options); | ||
if (!keys.includes('database')) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: 'Must provide a database name', | ||
}); | ||
} | ||
const dbName = options.database; | ||
if (!keys.includes('table')) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: 'Must provide a table name', | ||
}); | ||
} | ||
const tableName = options.table; | ||
keys = Object.keys(this._dbDict); | ||
if (!keys.includes(dbName)) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: 'IsDBExists command failed: No available ' + | ||
'connection for ' + | ||
dbName, | ||
}); | ||
} | ||
const mDB = this._dbDict[dbName]; | ||
try { | ||
const res = yield mDB.isTableExists(tableName); | ||
return Promise.resolve({ result: res.result }); | ||
} | ||
catch (err) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: `isTableExists: ${err.message}`, | ||
}); | ||
} | ||
}); | ||
} | ||
getDatabaseList() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// get the database folder | ||
const pathDatabase = this._uFile.getDatabasesPath(); | ||
// get the list of databases | ||
const files = yield this._uFile.getFileList(pathDatabase); | ||
return Promise.resolve({ | ||
values: files, | ||
}); | ||
}); | ||
} | ||
addSQLiteSuffix(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const folderPath = options.folderPath | ||
? options.folderPath | ||
: 'default'; | ||
try { | ||
yield this._uMigrate.addSQLiteSuffix(folderPath); | ||
return Promise.resolve({ | ||
result: true, | ||
}); | ||
} | ||
catch (err) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: `addSQLiteSuffix: ${err.message}`, | ||
}); | ||
} | ||
}); | ||
} | ||
deleteOldDatabases(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const folderPath = options.folderPath | ||
? options.folderPath | ||
: 'default'; | ||
try { | ||
yield this._uMigrate.deleteOldDatabases(folderPath); | ||
return Promise.resolve({ | ||
result: true, | ||
}); | ||
} | ||
catch (err) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: `deleteOldDatabases: ${err.message}`, | ||
}); | ||
} | ||
}); | ||
} | ||
deleteDatabase(options) { | ||
@@ -373,0 +478,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -75,3 +75,3 @@ declare module '@capacitor/core' { | ||
/** | ||
* Check is a SQLite database exists | ||
* Check if a SQLite database exists with opened connection | ||
* @param options: capSQLiteOptions | ||
@@ -83,2 +83,16 @@ * @returns Promise<capSQLiteResult> | ||
/** | ||
* Check if a SQLite database exists without connection | ||
* @param options: capSQLiteOptions | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 | ||
*/ | ||
isDatabase(options: capSQLiteOptions): Promise<capSQLiteResult>; | ||
/** | ||
* Check if a table exists in a SQLite database | ||
* @param options: capSQLiteTableOptions | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 | ||
*/ | ||
isTableExists(options: capSQLiteTableOptions): Promise<capSQLiteResult>; | ||
/** | ||
* Delete a SQLite database | ||
@@ -146,2 +160,22 @@ * @param options: capSQLiteOptions | ||
copyFromAssets(): Promise<capSQLiteResult>; | ||
/** | ||
* Get the database list | ||
* @returns Promise<capSQLiteValues> | ||
* @since 2.9.10 refactor | ||
*/ | ||
getDatabaseList(): Promise<capSQLiteValues>; | ||
/** | ||
* Add SQLIte Suffix to existing databases | ||
* @param options: capSQLitePathOptions | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 refactor | ||
*/ | ||
addSQLiteSuffix(options: capSQLitePathOptions): Promise<capSQLiteResult>; | ||
/** | ||
* Delete Old Cordova databases | ||
* @param options: capSQLitePathOptions | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 refactor | ||
*/ | ||
deleteOldDatabases(options: capSQLitePathOptions): Promise<capSQLiteResult>; | ||
} | ||
@@ -278,2 +312,18 @@ export interface capEchoOptions { | ||
} | ||
export interface capSQLitePathOptions { | ||
/** | ||
* The folder path of existing databases | ||
*/ | ||
folderPath?: string; | ||
} | ||
export interface capSQLiteTableOptions { | ||
/** | ||
* The database name | ||
*/ | ||
database?: string; | ||
/** | ||
* The table name | ||
*/ | ||
table?: string; | ||
} | ||
export interface capEchoResult { | ||
@@ -484,2 +534,9 @@ /** | ||
/** | ||
* Check if a connection exists | ||
* @param database | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 refactor | ||
*/ | ||
isConnection(database: string): Promise<capSQLiteResult>; | ||
/** | ||
* Retrieve an existing database connection | ||
@@ -530,2 +587,29 @@ * @param database | ||
copyFromAssets(): Promise<capSQLiteResult>; | ||
/** | ||
* Check if a database exists | ||
* @param database | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 refactor | ||
*/ | ||
isDatabase(database: string): Promise<capSQLiteResult>; | ||
/** | ||
* Get the database list | ||
* @returns Promise<capSQLiteValues> | ||
* @since 2.9.10 refactor | ||
*/ | ||
getDatabaseList(): Promise<capSQLiteValues>; | ||
/** | ||
* Add SQLIte Suffix to existing databases | ||
* @param folderPath | ||
* @returns Promise<capSQLiteValues> | ||
* @since 2.9.10 refactor | ||
*/ | ||
addSQLiteSuffix(folderPath?: string): Promise<capSQLiteResult>; | ||
/** | ||
* Delete Old Cordova databases | ||
* @param folderPath | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 refactor | ||
*/ | ||
deleteOldDatabases(folderPath?: string): Promise<capSQLiteResult>; | ||
} | ||
@@ -543,2 +627,3 @@ /** | ||
closeConnection(database: string): Promise<capSQLiteResult>; | ||
isConnection(database: string): Promise<capSQLiteResult>; | ||
retrieveConnection(database: string): Promise<SQLiteDBConnection | null | undefined>; | ||
@@ -550,2 +635,6 @@ retrieveAllConnections(): Promise<Map<string, SQLiteDBConnection>>; | ||
copyFromAssets(): Promise<capSQLiteResult>; | ||
isDatabase(database: string): Promise<capSQLiteResult>; | ||
getDatabaseList(): Promise<capSQLiteValues>; | ||
addSQLiteSuffix(folderPath?: string): Promise<capSQLiteResult>; | ||
deleteOldDatabases(folderPath?: string): Promise<capSQLiteResult>; | ||
} | ||
@@ -611,2 +700,8 @@ /** | ||
/** | ||
* Check if a SQLite DB Connection exists | ||
* @returns Promise<capSQLiteResult> | ||
* @since 2.9.10 refactor | ||
*/ | ||
isTable(table: string): Promise<capSQLiteResult>; | ||
/** | ||
* Delete a SQLite DB Connection | ||
@@ -659,2 +754,3 @@ * @returns Promise<capSQLiteResult> | ||
isExists(): Promise<capSQLiteResult>; | ||
isTable(table: string): Promise<capSQLiteResult>; | ||
delete(): Promise<capSQLiteResult>; | ||
@@ -661,0 +757,0 @@ createSyncTable(): Promise<capSQLiteChanges>; |
@@ -57,2 +57,9 @@ import { __awaiter } from "tslib"; | ||
} | ||
isConnection(database) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let res = {}; | ||
res.result = this._connectionDict.has(database); | ||
return res; | ||
}); | ||
} | ||
retrieveConnection(database) { | ||
@@ -102,2 +109,24 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
isDatabase(database) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.sqlite.isDatabase({ database: database }); | ||
}); | ||
} | ||
getDatabaseList() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.sqlite.getDatabaseList(); | ||
}); | ||
} | ||
addSQLiteSuffix(folderPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = folderPath ? folderPath : 'default'; | ||
return yield this.sqlite.addSQLiteSuffix({ folderPath: path }); | ||
}); | ||
} | ||
deleteOldDatabases(folderPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = folderPath ? folderPath : 'default'; | ||
return yield this.sqlite.deleteOldDatabases({ folderPath: path }); | ||
}); | ||
} | ||
} | ||
@@ -194,2 +223,11 @@ /** | ||
} | ||
isTable(table) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield this.sqlite.isTableExists({ | ||
database: this.dbName, | ||
table: table, | ||
}); | ||
return res; | ||
}); | ||
} | ||
delete() { | ||
@@ -196,0 +234,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -147,2 +147,3 @@ import { UtilsFile } from './utilsFile'; | ||
} | ||
/** | ||
@@ -185,2 +186,22 @@ * DeleteDB | ||
} | ||
async isTableExists(tableName: string): Promise<any> { | ||
const isOpen: boolean = this._isDBOpen; | ||
try { | ||
const retB = await this._uJson.isTableExists( | ||
this._mDB, | ||
isOpen, | ||
tableName, | ||
); | ||
if (retB) { | ||
return { result: true }; | ||
} else { | ||
return { | ||
result: false, | ||
message: `IsTableExists: table ${tableName} does not exist`, | ||
}; | ||
} | ||
} catch (err) { | ||
return { result: false, message: `IsTableExists: ${err.message}` }; | ||
} | ||
} | ||
/** | ||
@@ -187,0 +208,0 @@ * CreateSyncTable |
@@ -66,2 +66,16 @@ export class UtilsFile { | ||
/** | ||
* GetCustomerPath | ||
* get the customer path | ||
*/ | ||
public getCustomerPath(custPath: string): string { | ||
return this.Path.join(this.HomeDir, custPath); | ||
} | ||
/** | ||
* GetCustomerFilePath | ||
* get the customer file path | ||
*/ | ||
public getCustomerFilePath(custPath: string, file: string): string { | ||
return this.Path.join(custPath, file); | ||
} | ||
/** | ||
* GetDatabasesPath | ||
@@ -210,2 +224,19 @@ * get the database folder path | ||
} | ||
public copyFile( | ||
fromPath: string, | ||
fromFile: string, | ||
toPath: string, | ||
toFile: string, | ||
): Promise<void> { | ||
return new Promise(async (resolve, reject) => { | ||
const fPath: string = this.Path.join(fromPath, fromFile); | ||
const tPath: string = this.Path.join(toPath, toFile); | ||
try { | ||
this.NodeFs.copyFileSync(fPath, tPath); | ||
resolve(); | ||
} catch (err) { | ||
reject(new Error(`CopyFile: ${err.message}`)); | ||
} | ||
}); | ||
} | ||
/** | ||
@@ -212,0 +243,0 @@ * DeleteFileName |
@@ -22,2 +22,4 @@ import { WebPlugin } from '@capacitor/core'; | ||
capSQLiteSyncDate, | ||
capSQLiteTableOptions, | ||
capSQLitePathOptions, | ||
JsonSQLite, | ||
@@ -28,5 +30,4 @@ } from './definitions'; | ||
import { UtilsJson } from './electron-utils/ImportExportJson/utilsJson'; | ||
import { UtilsMigrate } from './electron-utils/utilsMigrate'; | ||
//1234567890123456789012345678901234567890123456789012345678901234567890 | ||
const { remote } = require('electron'); | ||
@@ -40,2 +41,3 @@ export class CapacitorSQLiteElectronWeb | ||
private _uJson: UtilsJson = new UtilsJson(); | ||
private _uMigrate: UtilsMigrate = new UtilsMigrate(); | ||
private _osType: string; | ||
@@ -396,2 +398,103 @@ private _versionUpgrades: Record< | ||
} | ||
async isDatabase(options: capSQLiteOptions): Promise<capSQLiteResult> { | ||
let keys = Object.keys(options); | ||
if (!keys.includes('database')) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: 'Must provide a database name', | ||
}); | ||
} | ||
const dbName: string = options.database!; | ||
const isExists: boolean = this._uFile.isFileExists(dbName + 'SQLite.db'); | ||
return Promise.resolve({ | ||
result: isExists, | ||
}); | ||
} | ||
async isTableExists( | ||
options: capSQLiteTableOptions, | ||
): Promise<capSQLiteResult> { | ||
let keys = Object.keys(options); | ||
if (!keys.includes('database')) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: 'Must provide a database name', | ||
}); | ||
} | ||
const dbName: string = options.database!; | ||
if (!keys.includes('table')) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: 'Must provide a table name', | ||
}); | ||
} | ||
const tableName: string = options.table!; | ||
keys = Object.keys(this._dbDict); | ||
if (!keys.includes(dbName)) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: | ||
'IsDBExists command failed: No available ' + | ||
'connection for ' + | ||
dbName, | ||
}); | ||
} | ||
const mDB = this._dbDict[dbName]; | ||
try { | ||
const res: any = await mDB.isTableExists(tableName); | ||
return Promise.resolve({ result: res.result }); | ||
} catch (err) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: `isTableExists: ${err.message}`, | ||
}); | ||
} | ||
} | ||
async getDatabaseList(): Promise<capSQLiteValues> { | ||
// get the database folder | ||
const pathDatabase = this._uFile.getDatabasesPath(); | ||
// get the list of databases | ||
const files: string[] = await this._uFile.getFileList(pathDatabase); | ||
return Promise.resolve({ | ||
values: files, | ||
}); | ||
} | ||
async addSQLiteSuffix( | ||
options: capSQLitePathOptions, | ||
): Promise<capSQLiteResult> { | ||
const folderPath: string = options.folderPath | ||
? options.folderPath | ||
: 'default'; | ||
try { | ||
await this._uMigrate.addSQLiteSuffix(folderPath); | ||
return Promise.resolve({ | ||
result: true, | ||
}); | ||
} catch (err) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: `addSQLiteSuffix: ${err.message}`, | ||
}); | ||
} | ||
} | ||
async deleteOldDatabases( | ||
options: capSQLitePathOptions, | ||
): Promise<capSQLiteResult> { | ||
const folderPath: string = options.folderPath | ||
? options.folderPath | ||
: 'default'; | ||
try { | ||
await this._uMigrate.deleteOldDatabases(folderPath); | ||
return Promise.resolve({ | ||
result: true, | ||
}); | ||
} catch (err) { | ||
return Promise.resolve({ | ||
result: false, | ||
message: `deleteOldDatabases: ${err.message}`, | ||
}); | ||
} | ||
} | ||
async deleteDatabase(options: capSQLiteOptions): Promise<capSQLiteResult> { | ||
@@ -398,0 +501,0 @@ let keys = Object.keys(options); |
{ | ||
"name": "@capacitor-community/sqlite", | ||
"version": "2.9.9", | ||
"version": "2.9.10", | ||
"description": "Capacitor SQLite Plugin", | ||
@@ -17,2 +17,3 @@ "homepage": "https://github.com/capacitor-community/sqlite", | ||
"watch": "tsc --watch", | ||
"test": "echo \"No test specified\"", | ||
"docgen": "npm run docgenPlugin && npm run docgenConnection && npm run docgenDBConnection", | ||
@@ -89,4 +90,3 @@ "docgenPlugin": "docgen --api CapacitorSQLitePlugin --output-readme docs/API.md", | ||
"url": "https://github.com/capacitor-community/sqlite/issues" | ||
}, | ||
"dependencies": {} | ||
} | ||
} |
@@ -230,2 +230,7 @@ <p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p> | ||
| copyFromAssets | ✅ | ✅ | ✅ | ✅ | ❌ | | ||
| isDatabase | ✅ | ✅ | ✅ | ✅ | ❌ | | ||
| isTableExists | ✅ | ✅ | ✅ | ✅ | ❌ | | ||
| getDatabaseList | ✅ | ✅ | ✅ | ✅ | ❌ | | ||
| addSQLiteSuffix | ✅ | ✅ | ✅ | ✅ | ❌ | | ||
| deleteOldDatabases | ✅ | ✅ | ✅ | ✅ | ❌ | | ||
@@ -244,2 +249,4 @@ ## Documentation | ||
[MigratingCordovaDatabases_Documentation](https://github.com/capacitor-community/sqlite/blob/2.9.x/docs/MigratingCordovaDatabases.md) | ||
[Ionic/Angular_Usage_Documentation](https://github.com/capacitor-community/sqlite/blob/2.9.x/docs/Ionic-Angular-Usage.md) | ||
@@ -246,0 +253,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
248
17914
309
2956501
1