Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 27a5d8b
Showing
70 changed files
with
7,320 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
coverage | ||
|
||
# Build | ||
dist | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
root: true | ||
, parser: '@typescript-eslint/parser' | ||
, plugins: [ | ||
'@typescript-eslint' | ||
] | ||
, extends: [ | ||
'eslint:recommended' | ||
, 'plugin:@typescript-eslint/recommended' | ||
] | ||
, rules: { | ||
'no-constant-condition': 'off' | ||
, 'no-async-promise-executor': 'off' | ||
, '@typescript-eslint/no-inferrable-types': 'off' | ||
, '@typescript-eslint/ban-types': 'off' | ||
, '@typescript-eslint/no-empty-function': 'off' | ||
, '@typescript-eslint/ban-ts-comment': 'off' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Node.js CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [12.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install -g yarn | ||
- run: yarn install | ||
- run: yarn lint | ||
- run: yarn test | ||
env: | ||
CI: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# Build | ||
lib | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 BlackGlory <woshenmedoubuzhidao@blackglory.me> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# extra-sql-builder | ||
|
||
## Install | ||
|
||
```sh | ||
npm install --save extra-sql-builder | ||
# or | ||
yarn add extra-sql-builder | ||
``` | ||
|
||
## Motivation | ||
|
||
It is difficult to create SQLs dynamically: | ||
- Concatenating strings is ugly | ||
- Traditional SQL Builders are not intuitive. | ||
- ORMs are not intuitive, and have poor performance. | ||
|
||
## Usage | ||
|
||
```ts | ||
import { INSERT_INTO, VALUES, text, sql } from 'extra-sql-builder' | ||
|
||
// INSERT INTO my_table (id, value) | ||
// VALUES (1, 'hello'), (2, 'world'); | ||
|
||
const cond = true | ||
|
||
const result1 = sql( | ||
INSERT_INTO('my_table', ['id', 'value']) | ||
, VALUES( | ||
['1', text('hello')], | ||
cond && ['2', text('world')] | ||
) | ||
) | ||
|
||
// or | ||
const result2 = sql( | ||
'INSERT INTO my_table (id, value)' | ||
, VALUES( | ||
['1', text('hello')], | ||
cond && ['2', text('world')] | ||
) | ||
) | ||
|
||
// or | ||
const result3 = ` | ||
INSERT INTO my_table (id, value) | ||
${VALUES(['1', text('hello')], | ||
cond && ['2', text('world')])}; | ||
` | ||
|
||
// or | ||
const values = VALUES(['1', text('hello')]) | ||
if (cond) values.values.push(['2', text('world')]) | ||
const result4 = ` | ||
INSERT INTO my_table (id, value) | ||
${values}; | ||
` | ||
``` | ||
|
||
## What about SQL injection? | ||
|
||
As long as you don't take user input as a parameter, | ||
there will be no SQL injection vulnerability. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { AND, And } from '@fragments/and' | ||
|
||
describe('AND(condition: string) => And', () => { | ||
it('return And', () => { | ||
const result = AND(`id = 'test'`) | ||
|
||
expect(result).toBeInstanceOf(And) | ||
expect(`${result}`).toBe(`AND id = 'test'`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { DELETE_FROM, DeleteFrom } from '@fragments/delete-from' | ||
|
||
describe('DELETE_FROM(table: string) => DeleteFrom', () => { | ||
it('return DeleteFrom', () => { | ||
const result = DELETE_FROM('my_table') | ||
|
||
expect(result).toBeInstanceOf(DeleteFrom) | ||
expect(`${result}`).toBe('DELETE FROM my_table') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { FROM, From } from '@fragments/from' | ||
|
||
describe('FROM(...tables: string[]) => From', () => { | ||
describe('one table', () => { | ||
it('return From', () => { | ||
const result = FROM('my_table') | ||
|
||
expect(result).toBeInstanceOf(From) | ||
expect(`${result}`).toBe('FROM my_table') | ||
}) | ||
}) | ||
|
||
describe('more than one table', () => { | ||
it('return From', () => { | ||
const result = FROM('my_table1', 'my_table2') | ||
|
||
expect(result).toBeInstanceOf(From) | ||
expect(`${result}`).toBe('FROM my_table1, my_table2') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { FULL_OUTER_JOIN, FullOuterJoin } from '@fragments/full-outer-join' | ||
|
||
describe('FULL_OUTER_JOIN(table: string): FullOuterJoin', () => { | ||
it('return FullOuterJoin', () => { | ||
const result = FULL_OUTER_JOIN('my_table') | ||
|
||
expect(result).toBeInstanceOf(FullOuterJoin) | ||
expect(`${result}`).toBe('FULL OUTER JOIN my_table') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { GROUP_BY, GroupBy } from '@fragments/group-by' | ||
|
||
describe('GROUP_BY(...fields: string[]): GroupBy', () => { | ||
describe('one field', () => { | ||
it('return GroupBy', () => { | ||
const result = GROUP_BY('id') | ||
|
||
expect(result).toBeInstanceOf(GroupBy) | ||
expect(`${result}`).toBe('GROUP BY id') | ||
}) | ||
}) | ||
|
||
describe('more than one field', () => { | ||
const result = GROUP_BY('id1', 'id2') | ||
|
||
expect(result).toBeInstanceOf(GroupBy) | ||
expect(`${result}`).toBe('GROUP BY id1, id2') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { HAVING, Having } from '@fragments/having' | ||
|
||
describe('HAVING(condition: string): Having', () => { | ||
it('return Having', () => { | ||
const result = HAVING(`id = 'id'`) | ||
|
||
expect(result).toBeInstanceOf(Having) | ||
expect(`${result}`).toBe(`HAVING id = 'id'`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { INNER_JOIN, InnerJoin } from '@fragments/inner-join' | ||
|
||
describe('INNER_JOIN(table: string): InnerJoin', () => { | ||
it('return InnerJoin', () => { | ||
const result = INNER_JOIN('my_table') | ||
|
||
expect(result).toBeInstanceOf(InnerJoin) | ||
expect(`${result}`).toBe('INNER JOIN my_table') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { INSERT_INTO, InsertInto } from '@fragments/insert-into' | ||
|
||
describe('INSERT_INTO(table, fields: string[]): InsertInto', () => { | ||
describe('one field', () => { | ||
it('return InsertInto', () => { | ||
const result = INSERT_INTO('my_table', ['id']) | ||
|
||
expect(result).toBeInstanceOf(InsertInto) | ||
expect(`${result}`).toBe('INSERT INTO my_table (id)') | ||
}) | ||
}) | ||
|
||
describe('more than one field', () => { | ||
it('return InsertInto', () => { | ||
const result = INSERT_INTO('my_table', ['id1', 'id2']) | ||
|
||
expect(result).toBeInstanceOf(InsertInto) | ||
expect(`${result}`).toBe('INSERT INTO my_table (id1, id2)') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { INTO, Into } from '@fragments/into' | ||
|
||
describe('INTO(table: string): Into', () => { | ||
it('return Into', () => { | ||
const result = INTO('my_table') | ||
|
||
expect(result).toBeInstanceOf(Into) | ||
expect(`${result}`).toBe('INTO my_table') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { LEFT_OUTER_JOIN, LeftOuterJoin } from '@fragments/left-outer-join' | ||
|
||
describe('LEFT_OUTER_JOIN(table: string): LeftOuterJoin', () => { | ||
it('return LeftOuterJoin', () => { | ||
const result = LEFT_OUTER_JOIN('my_table') | ||
|
||
expect(result).toBeInstanceOf(LeftOuterJoin) | ||
expect(`${result}`).toBe('LEFT OUTER JOIN my_table') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { LIMIT, Limit } from '@fragments/limit' | ||
|
||
describe('LIMIT(limit: number): Limit', () => { | ||
it('return Limit', () => { | ||
const result = LIMIT(10) | ||
|
||
expect(result).toBeInstanceOf(Limit) | ||
expect(`${result}`).toBe('LIMIT 10') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { OFFSET, Offset } from '@fragments/offset' | ||
|
||
describe('OFFSET(offset: number): Offset', () => { | ||
it('return Offset', () => { | ||
const result = OFFSET(10) | ||
|
||
expect(result).toBeInstanceOf(Offset) | ||
expect(`${result}`).toBe('OFFSET 10') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ON, On } from '@fragments/on' | ||
|
||
describe('ON(condition: string): On', () => { | ||
it('return On', () => { | ||
const result = ON(`id = 'id'`) | ||
|
||
expect(result).toBeInstanceOf(On) | ||
expect(`${result}`).toBe(`ON id = 'id'`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { OR, Or } from '@fragments/or' | ||
|
||
describe('OR(condition: string): Or', () => { | ||
it('return Or', () => { | ||
const result = OR(`id = 'id'`) | ||
|
||
expect(result).toBeInstanceOf(Or) | ||
expect(`${result}`).toBe(`OR id = 'id'`) | ||
}) | ||
}) |
Oops, something went wrong.