react-sqlite-hook
Advanced tools
Comparing version 2.1.3 to 2.1.4
@@ -0,1 +1,12 @@ | ||
## 2.1.4 (2021-12-19) | ||
### Chore | ||
- update to @capacitor/core 3.3.3 | ||
- update to @capacitor-community/sqlite 3.3.3-1 | ||
### Added Features | ||
- add non-conformed database test | ||
## 2.1.2 (2021-11-07) | ||
@@ -2,0 +13,0 @@ |
{ | ||
"name": "react-sqlite-hook", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "React Hook for @Capacitor-community/sqlite plugin", | ||
@@ -45,9 +45,9 @@ "repository": { | ||
"peerDependencies": { | ||
"@capacitor-community/sqlite": "^3.2.5", | ||
"@capacitor/core": "^3.2.5", | ||
"@capacitor-community/sqlite": "^3.3.3-1", | ||
"@capacitor/core": "^3.3.3", | ||
"react": "^17.0.2" | ||
}, | ||
"devDependencies": { | ||
"@capacitor-community/sqlite": "3.2.5", | ||
"@capacitor/core": "3.2.5", | ||
"@capacitor-community/sqlite": "3.3.3-1", | ||
"@capacitor/core": "3.3.3", | ||
"@capacitor/docgen": "0.0.17", | ||
@@ -54,0 +54,0 @@ "@testing-library/react-hooks": "^5.1.2", |
import { AvailableResult } from './util/models'; | ||
import { SQLiteDBConnection, capSQLiteChanges, capSQLiteValues } from '@capacitor-community/sqlite'; | ||
import { SQLiteDBConnection, capSQLiteChanges, capSQLiteValues, capNCDatabasePathResult } from '@capacitor-community/sqlite'; | ||
export { SQLiteDBConnection }; | ||
@@ -109,2 +109,46 @@ export declare type SQLiteProps = { | ||
/** | ||
* Get a Non-Conformed database path | ||
* @param databasePath | ||
* @param version | ||
* @returns Promise<capNCDatabasePathResult> | ||
* @since 3.3.3-1 | ||
*/ | ||
getNCDatabasePath(folderPath: string, database: string): Promise<capNCDatabasePathResult>; | ||
/** | ||
* Create a Non-Conformed database connection | ||
* @param databasePath | ||
* @param version | ||
* @returns Promise<SQLiteDBConnection> | ||
* @since 3.3.3-1 | ||
*/ | ||
createNCConnection(databasePath: string, version?: number): Promise<SQLiteDBConnection>; | ||
/** | ||
* Retrieve a Non-Conformed database connection | ||
* @param databasePath | ||
* @returns Promise<SQLiteDBConnection> | ||
* @since 3.3.3-1 | ||
*/ | ||
retrieveNCConnection(databasePath: string): Promise<SQLiteDBConnection>; | ||
/** | ||
* Close a Non-Conformed database connection | ||
* @param databasePath | ||
* @returns Promise<void> | ||
* @since 3.3.3-1 | ||
*/ | ||
closeNCConnection(databasePath: string): Promise<void>; | ||
/** | ||
* Check if Non-Conformed database connection exists | ||
* @param databasePath | ||
* @returns Promise<Result> | ||
* @since 3.3.3-1 | ||
*/ | ||
isNCConnection(databasePath: string): Promise<Result>; | ||
/** | ||
* Check if Non-Conformed database exists | ||
* @param databasePath | ||
* @returns Promise<Result> | ||
* @since 3.3.3-1 | ||
*/ | ||
isNCDatabase(databasePath: string): Promise<Result>; | ||
/** | ||
* Get the database list | ||
@@ -111,0 +155,0 @@ * @returns Promise<capSQLiteValues> |
@@ -462,4 +462,144 @@ import { useCallback, useMemo, useEffect } from 'react'; | ||
}, [mSQLite]); | ||
/** | ||
* Get a Non-Conformed database path | ||
* @param databasePath | ||
* @param version | ||
* @returns Promise<capNCDatabasePathResult> | ||
* @since 3.3.3-1 | ||
*/ | ||
const getNCDatabasePath = useCallback(async (folderPath, database) => { | ||
if (folderPath == null || folderPath.length === 0) { | ||
return Promise.reject(new Error('Must provide a folder path')); | ||
} | ||
if (database == null || database.length === 0) { | ||
return Promise.reject(new Error('Must provide a database name')); | ||
} | ||
const mFolderPath = folderPath; | ||
const mDatabase = database; | ||
try { | ||
const r = await mSQLite.getNCDatabasePath(mFolderPath, mDatabase); | ||
if (r) { | ||
return Promise.resolve(r); | ||
} | ||
else { | ||
return Promise.reject("No returned database path"); | ||
} | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Create a Non-Conformed Database Connection | ||
* @param databasePath string | ||
* @param version number optional | ||
*/ | ||
const createNCConnection = useCallback(async (databasePath, version) => { | ||
if (databasePath == null || databasePath.length === 0) { | ||
return Promise.reject(new Error('Must provide a database path')); | ||
} | ||
const mDatabasePath = databasePath; | ||
const mVersion = version ? version : 1; | ||
try { | ||
const r = await mSQLite.createNCConnection(mDatabasePath, mVersion); | ||
if (r) { | ||
return Promise.resolve(r); | ||
} | ||
else { | ||
return Promise.reject("No returned NC connection"); | ||
} | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Retrieve a Non-Conformed Database Connection | ||
* @param databasePath string | ||
*/ | ||
const retrieveNCConnection = useCallback(async (databasePath) => { | ||
if (databasePath.length > 0) { | ||
try { | ||
const r = await mSQLite.retrieveNCConnection(databasePath); | ||
if (r) { | ||
return Promise.resolve(r); | ||
} | ||
else { | ||
return Promise.reject("No returned NC connection"); | ||
} | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} | ||
else { | ||
return Promise.reject('Must provide a database path'); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Close a Non-Conformed Database Connection | ||
* @param databasePath string | ||
*/ | ||
const closeNCConnection = useCallback(async (databasePath) => { | ||
if (databasePath.length > 0) { | ||
try { | ||
await mSQLite.closeNCConnection(databasePath); | ||
return Promise.resolve(); | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} | ||
else { | ||
return Promise.reject('Must provide a database path'); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Check if a Non-Conformed Database Connection exists | ||
* @param databasePath | ||
*/ | ||
const isNCConnection = useCallback(async (databasePath) => { | ||
if (databasePath.length > 0) { | ||
try { | ||
const r = await mSQLite.isNCConnection(databasePath); | ||
if (r) { | ||
return Promise.resolve(r); | ||
} | ||
else { | ||
return Promise.reject("No returned NC Connection"); | ||
} | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} | ||
else { | ||
return Promise.reject('Must provide a database path'); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Check if database exists | ||
* @param databasePath | ||
*/ | ||
const isNCDatabase = useCallback(async (databasePath) => { | ||
if (databasePath.length > 0) { | ||
try { | ||
const r = await mSQLite.isNCDatabase(databasePath); | ||
if (r) { | ||
return Promise.resolve(r); | ||
} | ||
else { | ||
return Promise.reject("No returned NC Connection"); | ||
} | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} | ||
else { | ||
return Promise.reject('Must provide a database path'); | ||
} | ||
}, [mSQLite]); | ||
if (!availableFeaturesN.useSQLite) { | ||
return Object.assign({ initWebStore: featureNotAvailableError, saveToStore: featureNotAvailableError, echo: featureNotAvailableError, getPlatform: featureNotAvailableError, getCapacitorSQLite: 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, getMigratableDbList: featureNotAvailableError, addSQLiteSuffix: featureNotAvailableError, deleteOldDatabases: featureNotAvailableError, checkConnectionsConsistency: featureNotAvailableError, isSecretStored: featureNotAvailableError, setEncryptionSecret: featureNotAvailableError, changeEncryptionSecret: featureNotAvailableError }, notAvailable); | ||
return Object.assign({ initWebStore: featureNotAvailableError, saveToStore: featureNotAvailableError, echo: featureNotAvailableError, getPlatform: featureNotAvailableError, getCapacitorSQLite: featureNotAvailableError, createConnection: featureNotAvailableError, closeConnection: featureNotAvailableError, retrieveConnection: featureNotAvailableError, retrieveAllConnections: featureNotAvailableError, closeAllConnections: featureNotAvailableError, addUpgradeStatement: featureNotAvailableError, importFromJson: featureNotAvailableError, isJsonValid: featureNotAvailableError, copyFromAssets: featureNotAvailableError, isConnection: featureNotAvailableError, isDatabase: featureNotAvailableError, getNCDatabasePath: featureNotAvailableError, createNCConnection: featureNotAvailableError, closeNCConnection: featureNotAvailableError, retrieveNCConnection: featureNotAvailableError, isNCConnection: featureNotAvailableError, isNCDatabase: featureNotAvailableError, getDatabaseList: featureNotAvailableError, getMigratableDbList: featureNotAvailableError, addSQLiteSuffix: featureNotAvailableError, deleteOldDatabases: featureNotAvailableError, checkConnectionsConsistency: featureNotAvailableError, isSecretStored: featureNotAvailableError, setEncryptionSecret: featureNotAvailableError, changeEncryptionSecret: featureNotAvailableError }, notAvailable); | ||
} | ||
@@ -473,5 +613,6 @@ else { | ||
isSecretStored, setEncryptionSecret, changeEncryptionSecret, | ||
initWebStore, saveToStore, isAvailable: true }; | ||
initWebStore, saveToStore, getNCDatabasePath, createNCConnection, | ||
closeNCConnection, retrieveNCConnection, isNCConnection, isNCDatabase, isAvailable: true }; | ||
} | ||
}; | ||
//# sourceMappingURL=useSQLite.js.map |
@@ -25,2 +25,8 @@ <p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p> | ||
* [`isDatabase(...)`](#isdatabase) | ||
* [`getNCDatabasePath(...)`](#getncdatabasepath) | ||
* [`createNCConnection(...)`](#createncconnection) | ||
* [`retrieveNCConnection(...)`](#retrievencconnection) | ||
* [`closeNCConnection(...)`](#closencconnection) | ||
* [`isNCConnection(...)`](#isncconnection) | ||
* [`isNCDatabase(...)`](#isncdatabase) | ||
* [`getDatabaseList()`](#getdatabaselist) | ||
@@ -271,2 +277,116 @@ * [`getMigratableDbList(...)`](#getmigratabledblist) | ||
### getNCDatabasePath(...) | ||
```typescript | ||
getNCDatabasePath(folderPath: string, database: string) => Promise<capNCDatabasePathResult> | ||
``` | ||
Get a Non-Conformed database path | ||
| Param | Type | | ||
| ---------------- | ------------------- | | ||
| **`folderPath`** | <code>string</code> | | ||
| **`database`** | <code>string</code> | | ||
**Returns:** <code>Promise<<a href="#capncdatabasepathresult">capNCDatabasePathResult</a>></code> | ||
**Since:** 3.3.3-1 | ||
-------------------- | ||
### createNCConnection(...) | ||
```typescript | ||
createNCConnection(databasePath: string, version?: number | undefined) => Promise<SQLiteDBConnection> | ||
``` | ||
Create a Non-Conformed database connection | ||
| Param | Type | | ||
| ------------------ | ------------------- | | ||
| **`databasePath`** | <code>string</code> | | ||
| **`version`** | <code>number</code> | | ||
**Returns:** <code>Promise<SQLiteDBConnection></code> | ||
**Since:** 3.3.3-1 | ||
-------------------- | ||
### retrieveNCConnection(...) | ||
```typescript | ||
retrieveNCConnection(databasePath: string) => Promise<SQLiteDBConnection> | ||
``` | ||
Retrieve a Non-Conformed database connection | ||
| Param | Type | | ||
| ------------------ | ------------------- | | ||
| **`databasePath`** | <code>string</code> | | ||
**Returns:** <code>Promise<SQLiteDBConnection></code> | ||
**Since:** 3.3.3-1 | ||
-------------------- | ||
### closeNCConnection(...) | ||
```typescript | ||
closeNCConnection(databasePath: string) => Promise<void> | ||
``` | ||
Close a Non-Conformed database connection | ||
| Param | Type | | ||
| ------------------ | ------------------- | | ||
| **`databasePath`** | <code>string</code> | | ||
**Since:** 3.3.3-1 | ||
-------------------- | ||
### isNCConnection(...) | ||
```typescript | ||
isNCConnection(databasePath: string) => Promise<Result> | ||
``` | ||
Check if Non-Conformed database connection exists | ||
| Param | Type | | ||
| ------------------ | ------------------- | | ||
| **`databasePath`** | <code>string</code> | | ||
**Returns:** <code>Promise<<a href="#result">Result</a>></code> | ||
**Since:** 3.3.3-1 | ||
-------------------- | ||
### isNCDatabase(...) | ||
```typescript | ||
isNCDatabase(databasePath: string) => Promise<Result> | ||
``` | ||
Check if Non-Conformed database exists | ||
| Param | Type | | ||
| ------------------ | ------------------- | | ||
| **`databasePath`** | <code>string</code> | | ||
**Returns:** <code>Promise<<a href="#result">Result</a>></code> | ||
**Since:** 3.3.3-1 | ||
-------------------- | ||
### getDatabaseList() | ||
@@ -512,2 +632,9 @@ | ||
#### capNCDatabasePathResult | ||
| Prop | Type | Description | | ||
| ---------- | ------------------- | --------------- | | ||
| **`path`** | <code>string</code> | String returned | | ||
#### capSQLiteValues | ||
@@ -514,0 +641,0 @@ |
{ | ||
"name": "react-sqlite-hook", | ||
"version": "2.1.3", | ||
"version": "2.1.4", | ||
"description": "React Hook for @Capacitor-community/sqlite plugin", | ||
@@ -45,9 +45,9 @@ "repository": { | ||
"peerDependencies": { | ||
"@capacitor-community/sqlite": "^3.2.5", | ||
"@capacitor/core": "^3.2.5", | ||
"@capacitor-community/sqlite": "^3.3.3-1", | ||
"@capacitor/core": "^3.3.3", | ||
"react": "^17.0.2" | ||
}, | ||
"devDependencies": { | ||
"@capacitor-community/sqlite": "3.2.5", | ||
"@capacitor/core": "3.2.5", | ||
"@capacitor-community/sqlite": "3.3.3-1", | ||
"@capacitor/core": "3.3.3", | ||
"@capacitor/docgen": "0.0.17", | ||
@@ -54,0 +54,0 @@ "@testing-library/react-hooks": "^5.1.2", |
@@ -7,3 +7,3 @@ import { useCallback, useMemo, useEffect } from 'react'; | ||
import { CapacitorSQLite, SQLiteDBConnection, SQLiteConnection, | ||
capSQLiteChanges, capSQLiteValues } from '@capacitor-community/sqlite'; | ||
capSQLiteChanges, capSQLiteValues, capNCDatabasePathResult } from '@capacitor-community/sqlite'; | ||
@@ -83,3 +83,3 @@ export { SQLiteDBConnection } | ||
*/ | ||
retrieveConnection(database: string,): Promise<SQLiteDBConnection>; | ||
retrieveConnection(database: string): Promise<SQLiteDBConnection>; | ||
/** | ||
@@ -119,2 +119,46 @@ * Retrieve all database connections | ||
/** | ||
* Get a Non-Conformed database path | ||
* @param databasePath | ||
* @param version | ||
* @returns Promise<capNCDatabasePathResult> | ||
* @since 3.3.3-1 | ||
*/ | ||
getNCDatabasePath(folderPath: string, database: string): Promise<capNCDatabasePathResult>; | ||
/** | ||
* Create a Non-Conformed database connection | ||
* @param databasePath | ||
* @param version | ||
* @returns Promise<SQLiteDBConnection> | ||
* @since 3.3.3-1 | ||
*/ | ||
createNCConnection(databasePath: string, version?: number): Promise<SQLiteDBConnection>; | ||
/** | ||
* Retrieve a Non-Conformed database connection | ||
* @param databasePath | ||
* @returns Promise<SQLiteDBConnection> | ||
* @since 3.3.3-1 | ||
*/ | ||
retrieveNCConnection(databasePath: string): Promise<SQLiteDBConnection>; | ||
/** | ||
* Close a Non-Conformed database connection | ||
* @param databasePath | ||
* @returns Promise<void> | ||
* @since 3.3.3-1 | ||
*/ | ||
closeNCConnection(databasePath: string): Promise<void>; | ||
/** | ||
* Check if Non-Conformed database connection exists | ||
* @param databasePath | ||
* @returns Promise<Result> | ||
* @since 3.3.3-1 | ||
*/ | ||
isNCConnection(databasePath: string): Promise<Result>; | ||
/** | ||
* Check if Non-Conformed database exists | ||
* @param databasePath | ||
* @returns Promise<Result> | ||
* @since 3.3.3-1 | ||
*/ | ||
isNCDatabase(databasePath: string): Promise<Result>; | ||
/** | ||
* Get the database list | ||
@@ -666,3 +710,135 @@ * @returns Promise<capSQLiteValues> | ||
}, [mSQLite]); | ||
/** | ||
* Get a Non-Conformed database path | ||
* @param databasePath | ||
* @param version | ||
* @returns Promise<capNCDatabasePathResult> | ||
* @since 3.3.3-1 | ||
*/ | ||
const getNCDatabasePath = useCallback(async (folderPath: string, database: string): Promise<capNCDatabasePathResult> => { | ||
if (folderPath == null || folderPath.length === 0) { | ||
return Promise.reject(new Error('Must provide a folder path')); | ||
} | ||
if (database == null || database.length === 0) { | ||
return Promise.reject(new Error('Must provide a database name')); | ||
} | ||
const mFolderPath: string = folderPath; | ||
const mDatabase: string = database; | ||
try { | ||
const r = await mSQLite.getNCDatabasePath( | ||
mFolderPath, mDatabase); | ||
if(r) { | ||
return Promise.resolve(r); | ||
} else { | ||
return Promise.reject("No returned database path"); | ||
} | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Create a Non-Conformed Database Connection | ||
* @param databasePath string | ||
* @param version number optional | ||
*/ | ||
const createNCConnection = useCallback(async (databasePath: string, version?: number) | ||
: Promise<SQLiteDBConnection> => { | ||
if (databasePath == null || databasePath.length === 0) { | ||
return Promise.reject(new Error('Must provide a database path')); | ||
} | ||
const mDatabasePath: string = databasePath; | ||
const mVersion: number = version ? version : 1; | ||
try { | ||
const r = await mSQLite.createNCConnection( | ||
mDatabasePath, mVersion); | ||
if(r) { | ||
return Promise.resolve(r); | ||
} else { | ||
return Promise.reject("No returned NC connection"); | ||
} | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Retrieve a Non-Conformed Database Connection | ||
* @param databasePath string | ||
*/ | ||
const retrieveNCConnection = useCallback(async (databasePath: string): Promise<SQLiteDBConnection> => { | ||
if(databasePath.length > 0) { | ||
try { | ||
const r = await mSQLite.retrieveNCConnection(databasePath); | ||
if(r) { | ||
return Promise.resolve(r); | ||
} else { | ||
return Promise.reject("No returned NC connection"); | ||
} | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} else { | ||
return Promise.reject('Must provide a database path'); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Close a Non-Conformed Database Connection | ||
* @param databasePath string | ||
*/ | ||
const closeNCConnection = useCallback(async (databasePath: string): Promise<void> => { | ||
if(databasePath.length > 0) { | ||
try { | ||
await mSQLite.closeNCConnection(databasePath); | ||
return Promise.resolve(); | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} else { | ||
return Promise.reject('Must provide a database path'); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Check if a Non-Conformed Database Connection exists | ||
* @param databasePath | ||
*/ | ||
const isNCConnection = useCallback(async (databasePath: string): Promise<Result> => { | ||
if(databasePath.length > 0) { | ||
try { | ||
const r = await mSQLite.isNCConnection(databasePath); | ||
if(r) { | ||
return Promise.resolve(r); | ||
} else { | ||
return Promise.reject("No returned NC Connection"); | ||
} | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} else { | ||
return Promise.reject('Must provide a database path'); | ||
} | ||
}, [mSQLite]); | ||
/** | ||
* Check if database exists | ||
* @param databasePath | ||
*/ | ||
const isNCDatabase = useCallback(async (databasePath: string): Promise<Result> => { | ||
if(databasePath.length > 0) { | ||
try { | ||
const r = await mSQLite.isNCDatabase(databasePath); | ||
if(r) { | ||
return Promise.resolve(r); | ||
} else { | ||
return Promise.reject("No returned NC Connection"); | ||
} | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} else { | ||
return Promise.reject('Must provide a database path'); | ||
} | ||
}, [mSQLite]); | ||
if (!availableFeaturesN.useSQLite) { | ||
@@ -686,2 +862,8 @@ return { | ||
isDatabase: featureNotAvailableError, | ||
getNCDatabasePath: featureNotAvailableError, | ||
createNCConnection: featureNotAvailableError, | ||
closeNCConnection: featureNotAvailableError, | ||
retrieveNCConnection: featureNotAvailableError, | ||
isNCConnection: featureNotAvailableError, | ||
isNCDatabase: featureNotAvailableError, | ||
getDatabaseList: featureNotAvailableError, | ||
@@ -704,5 +886,6 @@ getMigratableDbList: featureNotAvailableError, | ||
isSecretStored, setEncryptionSecret, changeEncryptionSecret, | ||
initWebStore, saveToStore, isAvailable: true}; | ||
initWebStore, saveToStore, getNCDatabasePath, createNCConnection, | ||
closeNCConnection, retrieveNCConnection, isNCConnection, isNCDatabase, isAvailable: true}; | ||
} | ||
} |
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
123604
2167