https://github.com/af/ouiql
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/af/ouiql
- Owner: af
- License: mit
- Created: 2017-07-07T04:03:33.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-18T04:25:16.000Z (almost 9 years ago)
- Last Synced: 2024-10-18T07:05:20.310Z (over 1 year ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ouiql
ORMless approach for working with SQL databases in Node, heavily inspired by [yesql](https://github.com/krisajenkins/yesql) and [this blog post](http://tapoueh.org/blog/2017/06/how-to-write-sql/)
Currently this is an alpha-quality WIP!
## Usage
Write your queries in SQL files, and then create a "store" object that reads them from the
filesystem and converts them into JavaScript functions.
**In `myproject/users/updateName.sql`:
```sql
UPDATE users SET name = :name WHERE id = :id;
```
**In `myproject/users/store.js`
```js
const ouiql = require('ouiql')
const pool = new require('pg').Pool({connectionString: 'postgresql:....'})
const backend = ouiql.makeBackend({sendQuery: pool.query.bind(pool)})
const userStore = ouiql.makeStore(backend, {
relation: 'users',
sqlPath: __dirname
})
// Now you can require userStore from elsewhere in your app and make a query like this:
userStore.updateName({id: 1, name: 'Richard Hendricks'}) // => Promise
```
## Conventions
All query functions:
* return a Promise
* accept a single object parameter that contains named arguments
## License
MIT