react-sqlite-hook
Advanced tools
Comparing version 1.0.0-alpha.4 to 1.0.0-beta.1
@@ -0,1 +1,12 @@ | ||
## 1.0.0-beta.1 (2020-12-28) REFACTOR | ||
## Chore | ||
- @capacitor/core@2.4.5 | ||
- @capacitor-community/sqlite@2.9.0-beta.1 | ||
## Added Features | ||
- Add importFromJson and isJsonValid methods | ||
## 1.0.0-alpha.4 (2020-12-05) REFACTOR | ||
@@ -2,0 +13,0 @@ |
{ | ||
"name": "react-sqlite-hook", | ||
"version": "1.0.0-alpha.2", | ||
"version": "1.0.0-alpha.3", | ||
"description": "React Hook for @Capacitor-community/sqlite plugin", | ||
@@ -47,8 +47,8 @@ "repository": { | ||
"react": "^17.0.1", | ||
"@capacitor/core": "^2.4.3", | ||
"@capacitor/core": "^2.4.5", | ||
"@capacitor-community/sqlite": "refactor" | ||
}, | ||
"devDependencies": { | ||
"@capacitor-community/sqlite": "^2.9.0-alpha.5", | ||
"@capacitor/core": "^2.4.3", | ||
"@capacitor-community/sqlite": "^2.9.0-beta.1", | ||
"@capacitor/core": "^2.4.5", | ||
"@capacitor/docgen": "0.0.10", | ||
@@ -55,0 +55,0 @@ "@testing-library/react-hooks": "^3.4.2", |
import { AvailableResult } from './util/models'; | ||
import '@capacitor-community/sqlite'; | ||
import { SQLiteDBConnection } from '@capacitor-community/sqlite'; | ||
import { SQLiteDBConnection, capSQLiteChanges } from '@capacitor-community/sqlite'; | ||
export { SQLiteDBConnection }; | ||
@@ -71,2 +71,16 @@ /** | ||
/** | ||
* Import a database From a JSON | ||
* @param jsonstring string | ||
* @returns Promise<Changes> | ||
* @since 2.9.0 refactor | ||
*/ | ||
importFromJson(jsonstring: string): Promise<capSQLiteChanges>; | ||
/** | ||
* Check the validity of a JSON Object | ||
* @param jsonstring string | ||
* @returns Promise<Result> | ||
* @since 2.9.0 refactor | ||
*/ | ||
isJsonValid(jsonstring: string): Promise<Result>; | ||
/** | ||
* Request Permissions | ||
@@ -73,0 +87,0 @@ * @returns Promise<Result> |
@@ -60,3 +60,9 @@ import { useCallback, useMemo } from 'react'; | ||
if (value) { | ||
return { value: value }; | ||
const r = await mSQLite.echo(value); | ||
if (r) { | ||
return r; | ||
} | ||
else { | ||
return { value: null }; | ||
} | ||
} | ||
@@ -66,3 +72,3 @@ else { | ||
} | ||
}, []); | ||
}, [mSQLite]); | ||
const getPlatform = useCallback(async () => { | ||
@@ -148,2 +154,28 @@ return { platform: platform }; | ||
/** | ||
* Import from Json | ||
* @param jsonstring string | ||
*/ | ||
const importFromJson = useCallback(async (jsonstring) => { | ||
const r = await mSQLite.importFromJson(jsonstring); | ||
if (r) { | ||
if (typeof r.changes != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return { changes: { changes: -1, lastId: -1 }, message: "Error in importFromJson" }; | ||
}, [mSQLite]); | ||
/** | ||
* IIs Json Valid | ||
* @param jsonstring string | ||
*/ | ||
const isJsonValid = useCallback(async (jsonstring) => { | ||
const r = await mSQLite.isJsonValid(jsonstring); | ||
if (r) { | ||
if (typeof r.result != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return { result: false, message: "Error in isJsonValid" }; | ||
}, [mSQLite]); | ||
/** | ||
* Add the upgrade Statement for database version upgrading | ||
@@ -182,3 +214,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, requestPermissions: 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, requestPermissions: featureNotAvailableError }, notAvailable); | ||
} | ||
@@ -188,5 +220,6 @@ else { | ||
retrieveConnection, retrieveAllConnections, closeAllConnections, | ||
addUpgradeStatement, requestPermissions, isAvailable: true }; | ||
addUpgradeStatement, importFromJson, isJsonValid, | ||
requestPermissions, isAvailable: true }; | ||
} | ||
}; | ||
//# sourceMappingURL=useSQLite.js.map |
@@ -20,2 +20,4 @@ <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) | ||
* [`importFromJson(...)`](#importfromjson) | ||
* [`isJsonValid(...)`](#isjsonvalid) | ||
* [`requestPermissions()`](#requestpermissions) | ||
@@ -177,2 +179,40 @@ * [Interfaces](#interfaces) | ||
### importFromJson(...) | ||
```typescript | ||
importFromJson(jsonstring: string) => Promise<capSQLiteChanges> | ||
``` | ||
Import a database From a JSON | ||
| Param | Type | Description | | ||
| ---------------- | ------------------- | ----------- | | ||
| **`jsonstring`** | <code>string</code> | string | | ||
**Returns:** <code>Promise<<a href="#capsqlitechanges">capSQLiteChanges</a>></code> | ||
**Since:** 2.9.0 refactor | ||
-------------------- | ||
### isJsonValid(...) | ||
```typescript | ||
isJsonValid(jsonstring: string) => Promise<Result> | ||
``` | ||
Check the validity of a JSON Object | ||
| Param | Type | Description | | ||
| ---------------- | ------------------- | ----------- | | ||
| **`jsonstring`** | <code>string</code> | string | | ||
**Returns:** <code>Promise<<a href="#result">Result</a>></code> | ||
**Since:** 2.9.0 refactor | ||
-------------------- | ||
### requestPermissions() | ||
@@ -221,3 +261,19 @@ | ||
#### capSQLiteChanges | ||
| Prop | Type | Description | | ||
| ------------- | ------------------------------------------- | ----------------------------------------- | | ||
| **`changes`** | <code><a href="#changes">Changes</a></code> | a returned <a href="#changes">Changes</a> | | ||
| **`message`** | <code>string</code> | a returned message | | ||
#### Changes | ||
| Prop | Type | Description | | ||
| ------------- | ------------------- | ---------------------------------------------------- | | ||
| **`changes`** | <code>number</code> | the number of changes from an execute or run command | | ||
| **`lastId`** | <code>number</code> | the lastId created from a run command | | ||
</docgen-api> | ||
{ | ||
"name": "react-sqlite-hook", | ||
"version": "1.0.0-alpha.4", | ||
"version": "1.0.0-beta.1", | ||
"description": "React Hook for @Capacitor-community/sqlite plugin", | ||
@@ -47,8 +47,8 @@ "repository": { | ||
"react": "^17.0.1", | ||
"@capacitor/core": "^2.4.3", | ||
"@capacitor/core": "^2.4.5", | ||
"@capacitor-community/sqlite": "refactor" | ||
}, | ||
"devDependencies": { | ||
"@capacitor-community/sqlite": "^2.9.0-alpha.5", | ||
"@capacitor/core": "^2.4.3", | ||
"@capacitor-community/sqlite": "^2.9.0-beta.1", | ||
"@capacitor/core": "^2.4.5", | ||
"@capacitor/docgen": "0.0.10", | ||
@@ -55,0 +55,0 @@ "@testing-library/react-hooks": "^3.4.2", |
@@ -8,3 +8,3 @@ import { useCallback, useMemo } from 'react'; | ||
import { SQLiteDBConnection, | ||
SQLiteConnection } from '@capacitor-community/sqlite'; | ||
SQLiteConnection, capSQLiteChanges } from '@capacitor-community/sqlite'; | ||
@@ -82,2 +82,17 @@ export { SQLiteDBConnection } | ||
/** | ||
* Import a database From a JSON | ||
* @param jsonstring string | ||
* @returns Promise<Changes> | ||
* @since 2.9.0 refactor | ||
*/ | ||
importFromJson(jsonstring: string): Promise<capSQLiteChanges>; | ||
/** | ||
* Check the validity of a JSON Object | ||
* @param jsonstring string | ||
* @returns Promise<Result> | ||
* @since 2.9.0 refactor | ||
*/ | ||
isJsonValid(jsonstring: string): Promise<Result>; | ||
/** | ||
* Request Permissions | ||
@@ -106,2 +121,4 @@ * @returns Promise<Result> | ||
} | ||
/** | ||
@@ -164,7 +181,12 @@ * useSQLite Hook | ||
if(value) { | ||
return {value: value}; | ||
const r = await mSQLite.echo(value); | ||
if(r) { | ||
return r; | ||
} else { | ||
return {value: null}; | ||
} | ||
} else { | ||
return {value: null}; | ||
} | ||
}, []); | ||
}, [mSQLite]); | ||
@@ -240,3 +262,3 @@ const getPlatform = useCallback(async (): Promise<any> => { | ||
if(r) { | ||
return r; | ||
return r; | ||
} | ||
@@ -259,2 +281,30 @@ return null; | ||
/** | ||
* Import from Json | ||
* @param jsonstring string | ||
*/ | ||
const importFromJson = useCallback(async (jsonstring: string) => { | ||
const r = await mSQLite.importFromJson(jsonstring); | ||
if(r) { | ||
if( typeof r.changes != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return {changes: {changes: -1, lastId: -1}, message: "Error in importFromJson"}; | ||
}, [mSQLite]); | ||
/** | ||
* IIs Json Valid | ||
* @param jsonstring string | ||
*/ | ||
const isJsonValid = useCallback(async (jsonstring: string) => { | ||
const r = await mSQLite.isJsonValid(jsonstring); | ||
if(r) { | ||
if( typeof r.result != 'undefined') { | ||
return r; | ||
} | ||
} | ||
return {result: false, message: "Error in isJsonValid"}; | ||
}, [mSQLite]); | ||
/** | ||
* Add the upgrade Statement for database version upgrading | ||
@@ -307,2 +357,4 @@ * @param dbName string | ||
addUpgradeStatement: featureNotAvailableError, | ||
importFromJson: featureNotAvailableError, | ||
isJsonValid: featureNotAvailableError, | ||
requestPermissions: featureNotAvailableError, | ||
@@ -314,5 +366,6 @@ ...notAvailable | ||
retrieveConnection, retrieveAllConnections, closeAllConnections, | ||
addUpgradeStatement, requestPermissions, isAvailable: true}; | ||
addUpgradeStatement, importFromJson, isJsonValid, | ||
requestPermissions, isAvailable: true}; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
69776
1119