53 lines
1.4 KiB
Markdown
53 lines
1.4 KiB
Markdown
|
# PawSQLite WebSQL Adapter
|
||
|
|
||
|
A WebSQL adapter for PawSQLite which offers many improvements over working with WebSQL natively. Most importantly, transactions do not commit automatically. This allows you to perform asynchronous operations during transactions and still guarantee data integrity.
|
||
|
|
||
|
## Installation
|
||
|
|
||
|
You can install using npm:
|
||
|
|
||
|
```bash
|
||
|
npm install -s git+https://git.n0m.org/n0m/PawSQLite.git
|
||
|
npm install -s git+https://git.n0m.org/n0m/PawSQLite-WebSQL-Adapter.git
|
||
|
```
|
||
|
|
||
|
## Usage
|
||
|
|
||
|
For more detailed usage, please see: [https://git.n0m.org/n0m/PawSQLite](https://git.n0m.org/n0m/PawSQLite)
|
||
|
|
||
|
```javascript
|
||
|
const PawSQLite = require("pawsqlite");
|
||
|
const PawSQLiteWebSQLAdapter = require("pawsqlite-websql-adapter");
|
||
|
|
||
|
PawSQLite.registerAdapter(PawSQLiteWebSQLAdapter)
|
||
|
|
||
|
const db = await PawSQLite.open("test", {
|
||
|
adapter: 'PawSQLiteWebSQLAdapter'
|
||
|
});
|
||
|
|
||
|
await db.sql(`
|
||
|
CREATE TABLE contacts (
|
||
|
contact_id INTEGER PRIMARY KEY,
|
||
|
first_name TEXT NOT NULL,
|
||
|
last_name TEXT NOT NULL
|
||
|
);
|
||
|
`);
|
||
|
|
||
|
const transaction = db.transaction();
|
||
|
|
||
|
console.log(await db.sql("SELECT * FROM contacts"));
|
||
|
|
||
|
await transaction.sql(
|
||
|
"INSERT INTO contacts (first_name, last_name) VALUES (?, ?)",
|
||
|
"John",
|
||
|
"Lennon"
|
||
|
);
|
||
|
|
||
|
await transaction.commit();
|
||
|
```
|
||
|
|
||
|
## Contributing
|
||
|
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
||
|
|
||
|
## License
|
||
|
[MIT](https://choosealicense.com/licenses/mit/)
|