https://github.com/vasyas/interpolated-sql
https://github.com/vasyas/interpolated-sql
javascript mysql nodejs orm sql typescript
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/vasyas/interpolated-sql
- Owner: vasyas
- Created: 2018-03-30T10:13:43.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-02-11T00:34:15.000Z (over 4 years ago)
- Last Synced: 2025-08-09T08:45:19.386Z (11 months 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: "my@domain.com", 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