This module provides functionality of generating an SQL query from an object.
It supports SELECT, INSERT, UPDATE, DELETE, DROP AND CREATE statements.
TYPE ORDER CONDITION LIMIT
object.queryType object.order.columns object.condition.columns object.limit.count
object.order.directions object.condition.operators
object.condition.values
object.condition.logicalOperators
SELECT INSERT UPDATE DROP
object.select.table object.insert.table object.update.table object.drop.table
object.select.columns object.insert.columns object.update.columns
object.insert.values object.update.values
DELETE CREATE
object.delete.table object.create.table
object.create.columns
object.create.types
object.create.constrains
All parameters are type of array with string values.
let query = new Query({
queryType: ["SELECT"],
select: {
table: ["test"],
columns: ["firstColumn"]
},
order: {
columns: ["firstColumn", "secondColumn", "thirdColumn"],
directions: ["DESC", "ASC"]
},
condition: {
columns: ["firstColumn"],
operators: ["="],
values: ["2"]
}
});
Generates SELECT (firstColumn) FROM test WHERE firstColumn = ? ORDER BY firstColumn DESC, secondColumn ASC, thirdColumn and [ '2' ]
query = new Query({
queryType: ["INSERT"],
insert: {
table: ["test"],
columns: ["firstColumn"],
values: ["1", "2"]
}
});
Generates INSERT INTO test(firstColumn) VALUES ? and [ [ [ '1', '2' ] ] ]