raw-query-strings
v1.0.5-2
Published
module to allows you to generate a raw query strings
Downloads
18
Maintainers
Readme
Raw Query Strings Builder
An npm module to allows you to generate a raw query strings.
Latest Changes Log
- 1.0.5-1: Remove Cursor clause option
Installation
Install raw-query-strings with npm :
npm install raw-query-strings
Features
- Get One :
rawQuery.generateOne(Query)
- Get Many :
rawQuery.generateMany(Query)
Usage/Examples
- Query Class
select : String[]
from: From
join: Join[]
where: Where[]
group: String[]
sort: Array[][]
limit: Integer
offset: Integer
From { source: String, as: String }
Join { [JoinTypes]: String, as: String, on: String }
Where { and: String } // for OR statement { or: String }
JoinTypes [ join, left_join, right_join, inner_join, full_join ]
{
select: ["*", "COUNT(p.*) AS post_count"],
from: { source: 'user', as: 'u' },
join: [
{
left_join: 'post', as: 'p', on: 'p.user_id = u.id'
}
],
where: [
{ and: 'id > 10' },
{ or: 'id <= 100'},
{ and: 'status is true' }
],
group: ["u.id"],
sort: [
["u.name", "asc"],
["u.createdAt", "asc"]
],
limit: 50,
offset: 0
}
- Examples
const rawQuery = require('raw-query-strings');
const query = {
select: ['*'],
from: { source: 'user', as: 'u' }
};
const getRawQuery = rawQuery.generateOne(query);
console.log(getRawQuery); // SELECT * FROM user AS u LIMIT 1