https://github.com/vasyas/interpolated-sql
https://github.com/vasyas/interpolated-sql
javascript mysql nodejs orm sql typescript
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/vasyas/interpolated-sql
- Owner: vasyas
- Created: 2018-03-30T10:13:43.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-02-11T00:34:15.000Z (over 3 years ago)
- Last Synced: 2024-03-05T10:03:09.163Z (over 1 year ago)
- Topics: javascript, mysql, nodejs, orm, sql, typescript
- Language: TypeScript
- Size: 129 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Make SQL queries using JavaScript tagged literals for parameters.
## Example
```
const id = 5
const user = await sql`select * from user where id = ${id}`
```Best used with MySQL, where you can do
```
const id = await sql`
insert into user
set ${{ email: "[email protected]", role: Role.ADMIN }}
`.insert()
```## Getting started
Get package
```
yarn install interpolated-sql
```Create your own exec function, that will bind sql creation and connection handling
```
import {Sql} from "interpolated-sql"
import mysql from "mysql2/promise"const connection = await mysql.createConnection({
host: "localhost",
user: "root",
database: "test",
})function exec(parts, ...params) {
return new Sql(parts, params, () => connection)
}async function getUsers() {
return await exec`select * from users`.all()
}
```## API
see src/sql.ts