Using all lowercase 'query' function name for the builder.

This commit is contained in:
mike12345567 2021-06-03 16:47:31 +01:00
parent f507daa46a
commit 20d7d36a16
2 changed files with 10 additions and 10 deletions

View File

@ -102,7 +102,7 @@ class SqlQueryBuilder {
this._limit = limit this._limit = limit
} }
buildQuery(json) { query(json) {
const { endpoint } = json const { endpoint } = json
const knex = require("knex")({ client: this._client }) const knex = require("knex")({ client: this._client })
const operation = endpoint.operation const operation = endpoint.operation

View File

@ -54,19 +54,19 @@ describe("SQL query builder", () => {
}) })
it("should test a basic read", () => { it("should test a basic read", () => {
const query = sql.buildQuery(generateReadJson()) const query = sql.query(generateReadJson())
expect(query).toEqual(`select * from "${TABLE_NAME}" limit ${limit}`) expect(query).toEqual(`select * from "${TABLE_NAME}" limit ${limit}`)
}) })
it("should test a read with specific columns", () => { it("should test a read with specific columns", () => {
const query = sql.buildQuery(generateReadJson({ const query = sql.query(generateReadJson({
fields: ["name", "age"] fields: ["name", "age"]
})) }))
expect(query).toEqual(`select "name", "age" from "${TABLE_NAME}" limit ${limit}`) expect(query).toEqual(`select "name", "age" from "${TABLE_NAME}" limit ${limit}`)
}) })
it("should test a where string starts with read", () => { it("should test a where string starts with read", () => {
const query = sql.buildQuery(generateReadJson({ const query = sql.query(generateReadJson({
filters: { filters: {
string: { string: {
name: "John", name: "John",
@ -77,7 +77,7 @@ describe("SQL query builder", () => {
}) })
it("should test a where range read", () => { it("should test a where range read", () => {
const query = sql.buildQuery(generateReadJson({ const query = sql.query(generateReadJson({
filters: { filters: {
range: { range: {
age: { age: {
@ -91,7 +91,7 @@ describe("SQL query builder", () => {
}) })
it("should test an create statement", () => { it("should test an create statement", () => {
const query = sql.buildQuery(generateCreateJson(TABLE_NAME, { const query = sql.query(generateCreateJson(TABLE_NAME, {
name: "Michael", name: "Michael",
age: 45, age: 45,
})) }))
@ -99,7 +99,7 @@ describe("SQL query builder", () => {
}) })
it("should test an update statement", () => { it("should test an update statement", () => {
const query = sql.buildQuery(generateUpdateJson(TABLE_NAME, { const query = sql.query(generateUpdateJson(TABLE_NAME, {
name: "John" name: "John"
}, { }, {
equal: { equal: {
@ -110,7 +110,7 @@ describe("SQL query builder", () => {
}) })
it("should test a delete statement", () => { it("should test a delete statement", () => {
const query = sql.buildQuery(generateDeleteJson(TABLE_NAME, { const query = sql.query(generateDeleteJson(TABLE_NAME, {
equal: { equal: {
id: 1001, id: 1001,
} }
@ -119,12 +119,12 @@ describe("SQL query builder", () => {
}) })
it("should work with MS-SQL", () => { it("should work with MS-SQL", () => {
const query = new Sql("mssql", 10).buildQuery(generateReadJson()) const query = new Sql("mssql", 10).query(generateReadJson())
expect(query).toEqual(`select top (10) * from [${TABLE_NAME}]`) expect(query).toEqual(`select top (10) * from [${TABLE_NAME}]`)
}) })
it("should work with mySQL", () => { it("should work with mySQL", () => {
const query = new Sql("mysql", 10).buildQuery(generateReadJson()) const query = new Sql("mysql", 10).query(generateReadJson())
expect(query).toEqual(`select * from \`${TABLE_NAME}\` limit 10`) expect(query).toEqual(`select * from \`${TABLE_NAME}\` limit 10`)
}) })
}) })