Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abdurrahmanekr/sqlmaster
📦 ⚙️ SQL string maker.
https://github.com/abdurrahmanekr/sqlmaster
Last synced: 3 months ago
JSON representation
📦 ⚙️ SQL string maker.
- Host: GitHub
- URL: https://github.com/abdurrahmanekr/sqlmaster
- Owner: abdurrahmanekr
- License: mit
- Created: 2018-02-08T09:36:46.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-02-13T16:49:19.000Z (almost 4 years ago)
- Last Synced: 2024-09-15T06:52:45.911Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 9
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![sql_master_380x217](https://user-images.githubusercontent.com/15075759/36085081-1e61376c-0fd4-11e8-9318-6c1fac6eebe8.png)
# sqlmaster
SQL string maker.### Install
```
npm install sqlmaster --save
```
```javascript
const SQLMaster = require('sqlmaster');SQLMaster.init({
prepareType: '$',
xssFilter: true,
})// prepareType: '$' => SELECT * FROM users WHERE id = $1
// prepareType: 'tag' => SELECT * FROM users WHERE id = :id
```- [exec](#exec)
- [from](#from)
- [select](#select)
- [where](#where)
- [groupBy](#groupBy)
- [orderBy](#orderBy)
- [desc](#desc)
- [asc](#asc)
- [limit](#limit)
- [returning](#returning)
- [insert](#insert)
- [update](#update)
- [delete](#delete)## exec
It returns the output of the entire query.```javascript
SQLMaster
.from('users')
.delete()
.where('id = :id', {
':id': 65536
})
.exec()/*
{
text: 'DELETE FROM users WHERE id = $1',
values: [
65536
]
}
*/
```## from
It sets the query's master table.```javascript
SQLMaster.from('users')
```## select
It sets the query's 'select params'.```javascript
SQLMaster
.from('users')
.select([
"name",
["email", "RTRIM(email)"],
["count", "COUNT(*)"],
])// SELECT name, RTRIM(email) AS email, COUNT(*) AS count FROM users
```## where
It sets the query's 'where'.```javascript
SQLMaster
.from('users')
.where("id = :id", {
':id': 65536
})
.select([
"*",
])// SELECT name, RTRIM(email) AS email, COUNT(*) AS count FROM users WHERE id = $1
```## groupBy
It sets the query's 'group by'.```javascript
SQLMaster
.from('users')
.groupBy('name, email')
.select([
"name",
[ "email", "RTRIM(email)"],
["count", "COUNT(*)"]
])// SELECT name, RTRIM(email) AS email, COUNT(*) AS count FROM users GROUP BY name, email
```## orderBy
It sets the query's 'order by'.```javascript
SQLMaster
.from('users')
.orderBy('name, email')
.select([
"name",
[ "email", "RTRIM(email)"],
])// SELECT name, RTRIM(email) AS email, COUNT(*) AS count FROM users GROUP BY name, email
```## desc
It sets the query's 'order by desc'.```javascript
SQLMaster
.from('users')
.orderBy('name, email')
.desc()
.select([
"*"
])// SELECT * FROM users ORDER BY name, email DESC
```## asc
It sets the query's 'order by asc'.```javascript
SQLMaster
.from('users')
.orderBy('name, email')
.asc()
.select([
"*"
])// SELECT * FROM users ORDER BY name, email ASC
```## limit
It sets the query's 'limit'.```javascript
SQLMaster
.from('users')
.orderBy('name, email')
.desc()
.select([
"*"
])// SELECT * FROM users LIMIT 200
```## returning
It sets the query's 'returning'.```javascript
SQLMaster
.from('users')
.insert({
name: "GitHub Support",
email: "[email protected]",
date: new Date(),
})
.returning('id')// INSERT INTO users (name, email, date) VALUES($1, $2, $3) RETURNING id
```## insert
It sets the query's 'insert'.```javascript
SQLMaster
.from('users')
.insert({
name: "GitHub Support",
email: "[email protected]",
date: new Date(),
})// INSERT INTO users (name, email, date) VALUES($1, $2, $3)
```## update
It sets the query's 'update'.```javascript
SQLMaster
.from('users')
.update({
name: "GitHub Support",
email: "[email protected]",
date: new Date(),
})
.where('id = :id', {
':id': 65536
})// UPDATE users SET name = $1, email = $2, date = $3 WHERE id = $4
```## delete
It sets the query's 'delete'.```javascript
SQLMaster
.from('users')
.delete()
.where('id = :id', {
':id': 65536
})// DELETE FROM users WHERE id = $1
```## Contributors
[@mlelyakan](https://github.com/mlelyakan) - SQLMaster Icon