Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yannickdot/taskqlite
A monadic interface for sqlite in Node
https://github.com/yannickdot/taskqlite
monadic-interface nodejs sqlite task wrapper
Last synced: about 6 hours ago
JSON representation
A monadic interface for sqlite in Node
- Host: GitHub
- URL: https://github.com/yannickdot/taskqlite
- Owner: YannickDot
- License: mit
- Created: 2017-05-11T14:31:17.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-29T22:29:09.000Z (over 7 years ago)
- Last Synced: 2024-11-04T18:12:41.117Z (3 days ago)
- Topics: monadic-interface, nodejs, sqlite, task, wrapper
- Language: JavaScript
- Homepage:
- Size: 43 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Taskqlite
Taskqlite is a wrapper for [node-sqlite3](https://github.com/mapbox/node-sqlite3) exposing a monadic interface. 🎁
## Install
Install taskqlite and sqlite
```
yarn add taskqlite sqlite3
```
And install a task data type like [Taskorama](https://github.com/YannickDot/Taskorama) or [Fluture](https://github.com/fluture-js/Fluture)```
yarn add taskorama
```## Demo
```jsconst sqlite3 = require('sqlite3').verbose()
const sqliteDB = new sqlite3.Database(':memory:')
const taskqlite = require('taskqlite')const Taskorama = require('taskorama').default
const Fluture = require('fluture')const Task = Taskorama // or const Task = Fluture :)
const database = taskqlite(Task, sqliteDB)
Task.of(`Let's use Tasks with sqlite`)
.chain(_ => database.run('CREATE TABLE lorem (info TEXT)'))
.chain(_ => database.prepare('INSERT INTO lorem VALUES (?)'))
.chain(stmt =>
Task.do(function*() {
for (num of [1, 2, 3, 4, 5]) {
yield stmt.run('Ipsum ' + num)
}
yield stmt.finalize()
})
)
.chain(_ => database.all('SELECT rowid AS id, info FROM lorem'))
.fork(
err => console.log('error ->', err),
res => console.log('done! ->', res)
)
```Logs :
```js
/*
done! -> [ { id: 1, info: 'Ipsum 1' },
{ id: 2, info: 'Ipsum 2' },
{ id: 3, info: 'Ipsum 3' },
{ id: 4, info: 'Ipsum 4' },
{ id: 5, info: 'Ipsum 5' } ]
*/
```