Socket
Socket
Sign inDemoInstall

react-sqlite-hook

Package Overview
Dependencies
7
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0-beta.1 to 1.0.0-beta.2

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## 1.0.0-beta.2 (2021-01-01) REFACTOR
### Bug Fixes
- Fix readme
- Fix test
## 1.0.0-beta.1 (2020-12-28) REFACTOR

@@ -2,0 +9,0 @@

2

dist/package.json
{
"name": "react-sqlite-hook",
"version": "1.0.0-alpha.3",
"version": "1.0.0-beta.1",
"description": "React Hook for @Capacitor-community/sqlite plugin",

@@ -5,0 +5,0 @@ "repository": {

@@ -74,3 +74,3 @@ import { AvailableResult } from './util/models';

* @returns Promise<Changes>
* @since 2.9.0 refactor
* @since 1.0.0 refactor
*/

@@ -82,3 +82,3 @@ importFromJson(jsonstring: string): Promise<capSQLiteChanges>;

* @returns Promise<Result>
* @since 2.9.0 refactor
* @since 1.0.0 refactor
*/

@@ -85,0 +85,0 @@ isJsonValid(jsonstring: string): Promise<Result>;

{
"name": "react-sqlite-hook",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "React Hook for @Capacitor-community/sqlite plugin",

@@ -5,0 +5,0 @@ "repository": {

@@ -12,7 +12,7 @@ <p align="center"><br><img src="https://avatars3.githubusercontent.com/u/16580653?v=4" width="128" height="128" /></p>

<p align="center">
<img src="https://img.shields.io/maintenance/yes/2020?style=flat-square" />
<img src="https://img.shields.io/maintenance/yes/2021?style=flat-square" />
<a href="https://www.npmjs.com/package/react-sqlite-hook"><img src="https://img.shields.io/npm/l/react-sqlite-hook?style=flat-square" /></a>
<br>
<a href="https://www.npmjs.com/package/react-sqlite-hook"><img src="https://img.shields.io/npm/dw/react-sqlite-hook?style=flat-square" /></a>
<a href="https://www.npmjs.com/package/react-sqlite-hook"><img src="https://img.shields.io/npm/v/react-sqlite-hook?style=flat-square" /></a>
<a href="https://www.npmjs.com/package/react-sqlite-hook"><img src="https://img.shields.io/npm/v/react-sqlite-hook/refactor?style=flat-square" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

@@ -44,159 +44,7 @@ <a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-1-orange?style=flat-square" /></a>

- in the project `app.tsx` file import the sqlite hook
The usage of `react-sqlite-hook`is demonstrated in
```ts
import { useSQLite } from 'react-sqlite-hook/dist';
- [Ionic/React_Usage_Documentation](https://github.com/capacitor-community/sqlite/blob/refactor/docs/Ionic-React-Usage.md)
...
export let sqlite: any;
const App: React.FC = () => {
// to use the hook as a singleton
const {echo, getPlatform, createConnection, closeConnection,
retrieveConnection, retrieveAllConnections, closeAllConnections,
addUpgradeStatement, requestPermissions,
isAvailable} = useSQLite();
sqlite = {echo: echo, getPlatform: getPlatform,
createConnection: createConnection,
closeConnection: closeConnection,
retrieveConnection: retrieveConnection,
retrieveAllConnections: retrieveAllConnections,
closeAllConnections: closeAllConnections,
addUpgradeStatement: addUpgradeStatement,
requestPermissions: requestPermissions,
isAvailable:isAvailable};
...
return (
...
)
};
export default App;
```
- in a project component
```ts
...
import { sqlite } from '../App';
import { SQLiteDBConnection, Result } from 'react-sqlite-hook/dist';
const NoEncryption: React.FC = () => {
const [log, setLog] = useState<string[]>([]);
useEffect( () => {
const testDatabaseNoEncryption = async (): Promise<Boolean> => {
setLog((log) => log.concat("* Starting testDatabaseNoEncryption *\n"));
// test the plugin with echo
let res: any = await sqlite.echo("Hello from echo");
if(res.value !== "Hello from echo") return false;
setLog((log) => log.concat("> Echo successful\n"));
// create a connection for testNew
res = await sqlite.createConnection("testNew");
if(res == null ) return false;
if((Object.keys(res)).includes("result") && !res.result) return false;
setLog((log) => log.concat("> createConnection " +
" 'testNew' successful\n"));
let db: SQLiteDBConnection = res;
// open testNew
res = await db.open();
if(!res.result) return false;
setLog((log) => log.concat("> open 'testNew' successful\n"));
// Drop tables if exists
res = await db.execute(dropTablesTablesNoEncryption);
if(res.changes.changes !== 0 &&
res.changes.changes !== 1) return false;
setLog((log) => log.concat(" Execute1 successful\n"));
// Create tables
res = await db.execute(createTablesNoEncryption);
if(res.changes.changes !== 0 &&
res.changes.changes !== 1) return false;
setLog((log) => log.concat(" Execute2 successful\n"));
// Insert two users with execute method
res = await db.execute(importTwoUsers);
if(res.changes.changes !== 2) return false;
setLog((log) => log.concat(" Execute3 successful\n"));
// Select all Users
res = await db.query("SELECT * FROM users");
if(res.values.length !== 2 ||
res.values[0].name !== "Whiteley" ||
res.values[1].name !== "Jones") return false;
setLog((log) => log.concat(" Select1 successful\n"));
// add one user with statement and values
let sqlcmd = "INSERT INTO users (name,email,age) VALUES (?,?,?)";
let values: Array<any> = ["Simpson","Simpson@example.com",69];
res = await db.run(sqlcmd,values);
if(res.changes.changes !== 1 ||
res.changes.lastId !== 3) return false;
setLog((log) => log.concat(" Run1 successful\n"));
// add one user with statement
sqlcmd = `INSERT INTO users (name,email,age) VALUES `+
`("Brown","Brown@example.com",15)`;
res = await db.run(sqlcmd);
if(res.changes.changes !== 1 ||
res.changes.lastId !== 4) return false;
setLog((log) => log.concat(" Run2 successful\n"));
// Select all Users
res = await db.query("SELECT * FROM users");
if(res.values.length !== 4) return false;
setLog((log) => log.concat(" Select2 successful\n"));
// Select Users with age > 35
sqlcmd = "SELECT name,email,age FROM users WHERE age > ?";
values = ["35"];
res = await db.query(sqlcmd,values);
if(res.values.length !== 2) return false;
setLog((log) => log
.concat(" Select with filter on age successful\n"));
// Close Connection NoEncryption
res = await sqlite.closeConnection("NoEncryption");
if(!res.result) {
return false;
}
return true;
}
if(sqlite.isAvailable) {
testDatabaseNoEncryption().then(res => {
if(res) {
setLog((log) => log
.concat("\n* The set of tests was successful *\n"));
} else {
setLog((log) => log
.concat("\n* The set of tests failed *\n"));
}
});
} else {
sqlite.getPlatform().then((ret: { platform: string; }) => {
setLog((log) => log.concat("\n* Not available for " +
ret.platform + " platform *\n"));
});
}
}, []);
return (
<IonCard className="container-noencryption">
<IonCardContent>
<pre>
<p>{log}</p>
</pre>
</IonCardContent>
</IonCard>
);
};
```
## Contributors ✨

@@ -203,0 +51,0 @@

@@ -42,3 +42,3 @@

__init: (isPluginAvailable: boolean, _platform: string) => {
init: (isPluginAvailable: boolean, _platform: string) => {
mIsPluginAvailable = isPluginAvailable;

@@ -49,2 +49,3 @@ platform = _platform;

getPlatform: () => platform,
platform: platform
}

@@ -151,3 +152,3 @@ }

await act(async () => {
capacitorMock.__init(true,'ios');
capacitorMock.init(true,'ios');
});

@@ -166,3 +167,3 @@

await act(async () => {
capacitorMock.__init(true,'android');
capacitorMock.init(true,'android');
});

@@ -185,3 +186,3 @@

await act(async () => {
capacitorMock.__init(true, 'electron');
capacitorMock.init(true, 'electron');
});

@@ -199,3 +200,3 @@ const r = renderHook(() => useSQLite());

await act(async () => {
capacitorMock.__init(false, 'web');
capacitorMock.init(false, 'web');
});

@@ -215,3 +216,3 @@ const r = renderHook(() => useSQLite());

await act(async () => {
capacitorMock.__init(true,'ios');
capacitorMock.init(true,'ios');
});

@@ -232,3 +233,3 @@

await act(async () => {
capacitorMock.__init(true,'ios');
capacitorMock.init(true,'ios');
});

@@ -249,3 +250,3 @@

await act(async () => {
capacitorMock.__init(true,'ios');
capacitorMock.init(true,'ios');
});

@@ -268,3 +269,3 @@

await act(async () => {
capacitorMock.__init(true,'ios');
capacitorMock.init(true,'ios');
});

@@ -290,3 +291,3 @@

await act(async () => {
capacitorMock.__init(true,'ios');
capacitorMock.init(true,'ios');
});

@@ -315,3 +316,3 @@

await act(async () => {
capacitorMock.__init(true,'ios');
capacitorMock.init(true,'ios');
});

@@ -318,0 +319,0 @@

@@ -84,3 +84,3 @@ import { useCallback, useMemo } from 'react';

* @returns Promise<Changes>
* @since 2.9.0 refactor
* @since 1.0.0 refactor
*/

@@ -92,3 +92,3 @@ importFromJson(jsonstring: string): Promise<capSQLiteChanges>;

* @returns Promise<Result>
* @since 2.9.0 refactor
* @since 1.0.0 refactor
*/

@@ -95,0 +95,0 @@ isJsonValid(jsonstring: string): Promise<Result>;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc