Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/roitinnovation/roit-sql-builder

Simple SQL query builder.
https://github.com/roitinnovation/roit-sql-builder

nodejs sql typescript

Last synced: about 2 months ago
JSON representation

Simple SQL query builder.

Awesome Lists containing this project

README

        

# ROIT SQL Builder

## Usage

Project structure must be like this:

```
root
│ README.md
└───src/
└───sql/
```
Create a class that mirrors your table:

```typescript
export class Person {
name: string
age: number
}
```

Create you SQL file with the parameters with @ in front of the name:
```sql
SELECT * FROM person p WHERE p.name = @name AND p.age = @age
```

Import the method and use it:

```typescript
import { buildQueryString } from '@roit/roit-sql-builder'

const person = new Person()
person.name = 'Keanu Reeves'
person.age = 46

const query = buildQueryString('sql-file-name.sql', person)
console.log(query)
// Output:
// SELECT * FROM person p WHERE p.name = Keanu Reeves AND p.age = 46