sql-query-factory
v1.1.12
Published
A typed SQL query builder.
Downloads
30
Readme
sql-query-factory
A typed SQL query builder.
how to use
SELECT
SELECT all
select("*").from("foo").build();
// => "SELECT * FROM foo;"
WHERE
select("*").from("foo").where("foo").like("bar").build();
// => `SELECT * FROM foo WHERE foo LIKE 'bar';`
select("*").from("table_name")
.where("column1").between(5).and(8)
.and("column2").in("foo", 2, "bar")
.build();
// => `SELECT * FROM table_name WHERE column1 BETWEEN 5 AND 8 AND column2 IN ('foo', 2, 'bar');`
ORDER BY
select("*").from("table_name")
.where("column1").equal("foo")
.orderBy("colimn1")
.build();
// => `SELECT * FROM table_name WHERE column1 = 'foo' ORDER BY colimn1;`
INSERT
insertInto("table_name")
.keys("foo", "bar", "hoge")
.values("foo", 2, "bar")
.build();
// => `INSERT INTO table_name (foo, bar, hoge) VALUES('foo', 2, 'bar');`
CREATE TABLE
createTable("table_name")
.column("column1").type("TEXT").notNull().primaryKey().unique()
.column("column2").type("INTEGER").autoIncrement()
.build();
// => `CREATE TABLE table_name ( column1 TEXT NOT NULL PRIMARY KEY UNIQUE, column2 INTEGER AUTO_INCREMENT);`
UPDATE
update("table_name")
.set("column1", "value")
.where("column2").equal("value")
.build();
// => `UPDATE table_name SET column1 = 'value' WHERE column2 = 'value';`