2021-03-04 22:14:08 -08:00
|
|
|
# PawSQLite Node Adapter
|
2021-03-02 23:16:52 -08:00
|
|
|
|
2021-03-04 22:14:08 -08:00
|
|
|
A Node adapter for PawSQLite using the [sqlite3 package](https://www.npmjs.com/package/sqlite3).
|
2021-03-02 23:16:52 -08:00
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
You can install using npm:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
npm install -s git+https://git.n0m.org/n0m/PawSQLite.git
|
2021-03-04 22:14:08 -08:00
|
|
|
npm install -s git+https://git.n0m.org/n0m/PawSQLite-Node-Adapter.git
|
2021-03-02 23:16:52 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
For more detailed usage, please see: [https://git.n0m.org/n0m/PawSQLite](https://git.n0m.org/n0m/PawSQLite)
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
const PawSQLite = require("pawsqlite");
|
2021-03-04 22:14:08 -08:00
|
|
|
const PawSQLiteNodeAdapter = require("pawsqlite-node-adapter");
|
2021-03-02 23:16:52 -08:00
|
|
|
|
2021-03-04 22:14:08 -08:00
|
|
|
PawSQLite.registerAdapter(PawSQLiteNodeAdapter)
|
2021-03-02 23:16:52 -08:00
|
|
|
|
|
|
|
const db = await PawSQLite.open("test", {
|
2021-03-04 22:14:08 -08:00
|
|
|
adapter: 'PawSQLiteNodeAdapter'
|
2021-03-02 23:16:52 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
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/)
|