react-sqlite-hook
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -0,1 +1,11 @@ | ||
## 1.0.1 (2021-02-16) REFACTOR | ||
## Added Features | ||
- isConnection method | ||
- isDatabase method | ||
- getDatabaseList method | ||
- addSQLiteSuffix method | ||
- deleteOldDatabases method | ||
## 1.0.0 (2021-01-25) REFACTOR | ||
@@ -2,0 +12,0 @@ |
{ | ||
"name": "react-sqlite-hook", | ||
"version": "1.0.0-beta.4", | ||
"version": "1.0.0", | ||
"description": "React Hook for @Capacitor-community/sqlite plugin", | ||
@@ -46,8 +46,8 @@ "repository": { | ||
"peerDependencies": { | ||
"react": "^17.0.1", | ||
"@capacitor-community/sqlite": "^2.9.12", | ||
"@capacitor/core": "^2.4.6", | ||
"@capacitor-community/sqlite": "latest" | ||
"react": "^17.0.1" | ||
}, | ||
"devDependencies": { | ||
"@capacitor-community/sqlite": "latest", | ||
"@capacitor-community/sqlite": "2.9.12", | ||
"@capacitor/core": "^2.4.6", | ||
@@ -54,0 +54,0 @@ "@capacitor/docgen": "0.0.14", |
import { AvailableResult } from './util/models'; | ||
import '@capacitor-community/sqlite'; | ||
import { SQLiteDBConnection, capSQLiteChanges } from '@capacitor-community/sqlite'; | ||
import { SQLiteDBConnection, capSQLiteChanges, capSQLiteValues } from '@capacitor-community/sqlite'; | ||
export { SQLiteDBConnection }; | ||
@@ -71,2 +71,36 @@ /** | ||
/** | ||
* Check if database connection exists | ||
* @param database | ||
* @returns Promise<Result> | ||
* @since 1.0.1 refactor | ||
*/ | ||
isConnection(database: string): Promise<Result>; | ||
/** | ||
* Check if database exists | ||
* @param database | ||
* @returns Promise<Result> | ||
* @since 1.0.1 refactor | ||
*/ | ||
isDatabase(database: string): Promise<Result>; | ||
/** | ||
* Get the database list | ||
* @returns Promise<capSQLiteValues> | ||
* @since 1.0.1 refactor | ||
*/ | ||
getDatabaseList(): Promise<capSQLiteValues>; | ||
/** | ||
* Add SQLIte Suffix to existing databases | ||
* @param folderPath | ||
* @returns Promise<Result> | ||
* @since 1.0.1 refactor | ||
*/ | ||
addSQLiteSuffix(folderPath?: string): Promise<Result>; | ||
/** | ||
* Delete Old Cordova databases | ||
* @param folderPath | ||
* @returns Promise<Result> | ||
* @since 1.0.1 refactor | ||
*/ | ||
deleteOldDatabases(folderPath?: string): Promise<Result>; | ||
/** | ||
* Import a database From a JSON | ||
@@ -73,0 +107,0 @@ * @param jsonstring string |
@@ -77,2 +77,76 @@ import { useCallback, useMemo } from 'react'; | ||
/** | ||
* Check if database connection exists | ||
* @param database | ||
*/ | ||
const isConnection = useCallback(async (dbName) => { | ||
if (dbName.length > 0) { | ||
const r = await mSQLite.isConnection(dbName); | ||
if (r) { | ||
if (typeof r.result != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return { result: false, message: "Error in isConnection" }; | ||
} | ||
return { result: false, message: "Must provide a database name" }; | ||
}, [mSQLite]); | ||
/** | ||
* Check if database exists | ||
* @param database | ||
*/ | ||
const isDatabase = useCallback(async (dbName) => { | ||
if (dbName.length > 0) { | ||
const r = await mSQLite.isDatabase(dbName); | ||
if (r) { | ||
if (typeof r.result != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return { result: false, message: "Error in isDatabase" }; | ||
} | ||
return { result: false, message: "Must provide a database name" }; | ||
}, [mSQLite]); | ||
/** | ||
* Get the database list | ||
* @returns Promise<capSQLiteValues> | ||
* @since 1.0.1 refactor | ||
*/ | ||
const getDatabaseList = useCallback(async () => { | ||
const r = await mSQLite.getDatabaseList(); | ||
if (r) { | ||
if (typeof r.values != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return { values: [], message: "Error in getDatabaseList" }; | ||
}, [mSQLite]); | ||
/** | ||
* Add SQLIte Suffix to existing databases | ||
* @param folderPath | ||
*/ | ||
const addSQLiteSuffix = useCallback(async (folderPath) => { | ||
const path = folderPath ? folderPath : "default"; | ||
const r = await mSQLite.addSQLiteSuffix(path); | ||
if (r) { | ||
if (typeof r.result != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return { result: false, message: "Error in addSQLiteSuffix" }; | ||
}, [mSQLite]); | ||
/** | ||
* Delete Old Cordova databases | ||
* @param folderPath | ||
*/ | ||
const deleteOldDatabases = useCallback(async (folderPath) => { | ||
const path = folderPath ? folderPath : "default"; | ||
const r = await mSQLite.deleteOldDatabases(path); | ||
if (r) { | ||
if (typeof r.result != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return { result: false, message: "Error in deleteOldDatabases" }; | ||
}, [mSQLite]); | ||
/** | ||
* Retrieve a Connection to the Database | ||
@@ -188,3 +262,3 @@ * @param dbName string | ||
if (!availableFeaturesN.useSQLite) { | ||
return Object.assign({ echo: featureNotAvailableError, getPlatform: featureNotAvailableError, createConnection: featureNotAvailableError, closeConnection: featureNotAvailableError, retrieveConnection: featureNotAvailableError, retrieveAllConnections: featureNotAvailableError, closeAllConnections: featureNotAvailableError, addUpgradeStatement: featureNotAvailableError, importFromJson: featureNotAvailableError, isJsonValid: featureNotAvailableError, copyFromAssets: featureNotAvailableError }, notAvailable); | ||
return Object.assign({ echo: featureNotAvailableError, getPlatform: featureNotAvailableError, createConnection: featureNotAvailableError, closeConnection: featureNotAvailableError, retrieveConnection: featureNotAvailableError, retrieveAllConnections: featureNotAvailableError, closeAllConnections: featureNotAvailableError, addUpgradeStatement: featureNotAvailableError, importFromJson: featureNotAvailableError, isJsonValid: featureNotAvailableError, copyFromAssets: featureNotAvailableError, isConnection: featureNotAvailableError, isDatabase: featureNotAvailableError, getDatabaseList: featureNotAvailableError, addSQLiteSuffix: featureNotAvailableError, deleteOldDatabases: featureNotAvailableError }, notAvailable); | ||
} | ||
@@ -195,2 +269,4 @@ else { | ||
addUpgradeStatement, importFromJson, isJsonValid, copyFromAssets, | ||
isConnection, isDatabase, getDatabaseList, addSQLiteSuffix, | ||
deleteOldDatabases, | ||
isAvailable: true }; | ||
@@ -197,0 +273,0 @@ } |
@@ -20,2 +20,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> | ||
* [`closeAllConnections()`](#closeallconnections) | ||
* [`isConnection(...)`](#isconnection) | ||
* [`isDatabase(...)`](#isdatabase) | ||
* [`getDatabaseList()`](#getdatabaselist) | ||
* [`addSQLiteSuffix(...)`](#addsqlitesuffix) | ||
* [`deleteOldDatabases(...)`](#deleteolddatabases) | ||
* [`importFromJson(...)`](#importfromjson) | ||
@@ -179,2 +184,93 @@ * [`isJsonValid(...)`](#isjsonvalid) | ||
### isConnection(...) | ||
```typescript | ||
isConnection(database: string) => Promise<Result> | ||
``` | ||
Check if database connection exists | ||
| Param | Type | | ||
| -------------- | ------------------- | | ||
| **`database`** | <code>string</code> | | ||
**Returns:** <code>Promise<<a href="#result">Result</a>></code> | ||
**Since:** 1.0.1 refactor | ||
-------------------- | ||
### isDatabase(...) | ||
```typescript | ||
isDatabase(database: string) => Promise<Result> | ||
``` | ||
Check if database exists | ||
| Param | Type | | ||
| -------------- | ------------------- | | ||
| **`database`** | <code>string</code> | | ||
**Returns:** <code>Promise<<a href="#result">Result</a>></code> | ||
**Since:** 1.0.1 refactor | ||
-------------------- | ||
### getDatabaseList() | ||
```typescript | ||
getDatabaseList() => Promise<capSQLiteValues> | ||
``` | ||
Get the database list | ||
**Returns:** <code>Promise<<a href="#capsqlitevalues">capSQLiteValues</a>></code> | ||
**Since:** 1.0.1 refactor | ||
-------------------- | ||
### addSQLiteSuffix(...) | ||
```typescript | ||
addSQLiteSuffix(folderPath?: string | undefined) => Promise<Result> | ||
``` | ||
Add SQLIte Suffix to existing databases | ||
| Param | Type | | ||
| ---------------- | ------------------- | | ||
| **`folderPath`** | <code>string</code> | | ||
**Returns:** <code>Promise<<a href="#result">Result</a>></code> | ||
**Since:** 1.0.1 refactor | ||
-------------------- | ||
### deleteOldDatabases(...) | ||
```typescript | ||
deleteOldDatabases(folderPath?: string | undefined) => Promise<Result> | ||
``` | ||
Delete Old Cordova databases | ||
| Param | Type | | ||
| ---------------- | ------------------- | | ||
| **`folderPath`** | <code>string</code> | | ||
**Returns:** <code>Promise<<a href="#result">Result</a>></code> | ||
**Since:** 1.0.1 refactor | ||
-------------------- | ||
### importFromJson(...) | ||
@@ -262,2 +358,10 @@ | ||
#### capSQLiteValues | ||
| Prop | Type | Description | | ||
| ------------- | ------------------- | -------------------------------- | | ||
| **`values`** | <code>any[]</code> | the data values list as an Array | | ||
| **`message`** | <code>string</code> | a returned message | | ||
#### capSQLiteChanges | ||
@@ -264,0 +368,0 @@ |
{ | ||
"name": "react-sqlite-hook", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "React Hook for @Capacitor-community/sqlite plugin", | ||
@@ -46,8 +46,8 @@ "repository": { | ||
"peerDependencies": { | ||
"react": "^17.0.1", | ||
"@capacitor-community/sqlite": "^2.9.12", | ||
"@capacitor/core": "^2.4.6", | ||
"@capacitor-community/sqlite": "latest" | ||
"react": "^17.0.1" | ||
}, | ||
"devDependencies": { | ||
"@capacitor-community/sqlite": "latest", | ||
"@capacitor-community/sqlite": "2.9.12", | ||
"@capacitor/core": "^2.4.6", | ||
@@ -54,0 +54,0 @@ "@capacitor/docgen": "0.0.14", |
@@ -7,4 +7,4 @@ import { useCallback, useMemo } from 'react'; | ||
import '@capacitor-community/sqlite'; | ||
import { SQLiteDBConnection, | ||
SQLiteConnection, capSQLiteChanges } from '@capacitor-community/sqlite'; | ||
import { SQLiteDBConnection, SQLiteConnection, | ||
capSQLiteChanges, capSQLiteValues } from '@capacitor-community/sqlite'; | ||
@@ -83,2 +83,36 @@ export { SQLiteDBConnection } | ||
/** | ||
* Check if database connection exists | ||
* @param database | ||
* @returns Promise<Result> | ||
* @since 1.0.1 refactor | ||
*/ | ||
isConnection(database: string): Promise<Result>; | ||
/** | ||
* Check if database exists | ||
* @param database | ||
* @returns Promise<Result> | ||
* @since 1.0.1 refactor | ||
*/ | ||
isDatabase(database: string): Promise<Result>; | ||
/** | ||
* Get the database list | ||
* @returns Promise<capSQLiteValues> | ||
* @since 1.0.1 refactor | ||
*/ | ||
getDatabaseList(): Promise<capSQLiteValues>; | ||
/** | ||
* Add SQLIte Suffix to existing databases | ||
* @param folderPath | ||
* @returns Promise<Result> | ||
* @since 1.0.1 refactor | ||
*/ | ||
addSQLiteSuffix(folderPath?: string): Promise<Result> | ||
/** | ||
* Delete Old Cordova databases | ||
* @param folderPath | ||
* @returns Promise<Result> | ||
* @since 1.0.1 refactor | ||
*/ | ||
deleteOldDatabases(folderPath?: string): Promise<Result>; | ||
/** | ||
* Import a database From a JSON | ||
@@ -192,3 +226,3 @@ * @param jsonstring string | ||
*/ | ||
const closeConnection = useCallback(async (dbName: string) => { | ||
const closeConnection = useCallback(async (dbName: string): Promise<Result> => { | ||
if(dbName.length > 0) { | ||
@@ -206,2 +240,81 @@ const r = await mSQLite.closeConnection(dbName); | ||
/** | ||
* Check if database connection exists | ||
* @param database | ||
*/ | ||
const isConnection = useCallback(async (dbName: string): Promise<Result> => { | ||
if(dbName.length > 0) { | ||
const r = await mSQLite.isConnection(dbName); | ||
if(r) { | ||
if( typeof r.result != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return {result: false, message: "Error in isConnection"}; | ||
} | ||
return {result: false, message: "Must provide a database name"}; | ||
}, [mSQLite]); | ||
/** | ||
* Check if database exists | ||
* @param database | ||
*/ | ||
const isDatabase = useCallback(async (dbName: string): Promise<Result> => { | ||
if(dbName.length > 0) { | ||
const r = await mSQLite.isDatabase(dbName); | ||
if(r) { | ||
if( typeof r.result != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return {result: false, message: "Error in isDatabase"}; | ||
} | ||
return {result: false, message: "Must provide a database name"}; | ||
}, [mSQLite]); | ||
/** | ||
* Get the database list | ||
* @returns Promise<capSQLiteValues> | ||
* @since 1.0.1 refactor | ||
*/ | ||
const getDatabaseList = useCallback(async (): Promise<capSQLiteValues> => { | ||
const r = await mSQLite.getDatabaseList(); | ||
if(r) { | ||
if( typeof r.values != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return {values: [], message: "Error in getDatabaseList"}; | ||
}, [mSQLite]); | ||
/** | ||
* Add SQLIte Suffix to existing databases | ||
* @param folderPath | ||
*/ | ||
const addSQLiteSuffix = useCallback(async (folderPath?: string): Promise<Result> => { | ||
const path: string = folderPath ? folderPath : "default" | ||
const r = await mSQLite.addSQLiteSuffix(path); | ||
if(r) { | ||
if( typeof r.result != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return {result: false, message: "Error in addSQLiteSuffix"}; | ||
}, [mSQLite]); | ||
/** | ||
* Delete Old Cordova databases | ||
* @param folderPath | ||
*/ | ||
const deleteOldDatabases = useCallback(async (folderPath?: string): Promise<Result> => { | ||
const path: string = folderPath ? folderPath : "default" | ||
const r = await mSQLite.deleteOldDatabases(path); | ||
if(r) { | ||
if( typeof r.result != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return {result: false, message: "Error in deleteOldDatabases"}; | ||
}, [mSQLite]); | ||
/** | ||
* Retrieve a Connection to the Database | ||
@@ -335,2 +448,7 @@ * @param dbName string | ||
copyFromAssets: featureNotAvailableError, | ||
isConnection: featureNotAvailableError, | ||
isDatabase: featureNotAvailableError, | ||
getDatabaseList: featureNotAvailableError, | ||
addSQLiteSuffix: featureNotAvailableError, | ||
deleteOldDatabases: featureNotAvailableError, | ||
...notAvailable | ||
@@ -342,2 +460,4 @@ }; | ||
addUpgradeStatement, importFromJson, isJsonValid, copyFromAssets, | ||
isConnection, isDatabase, getDatabaseList, addSQLiteSuffix, | ||
deleteOldDatabases, | ||
isAvailable: true}; | ||
@@ -344,0 +464,0 @@ } |
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
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
74013
1286