-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rewrite in typescript (wip) * add build to gitignore * fix bug * fix bug (bis) * update jest config * update helpers * update tests * remove pg.js and sql.js * update build script * include right files when publishing * improve scripts * remove types folder * remove types folder (bis) * clean stuff * clean stuff (bis) * fix linter * fix linting issues * remove dtslint in circleci * simplify things * fix tests * better types/interfaces * update readme * fix yarn run lint * add IPGQueryable * fix tests * move expression counter into SqlContainer
- Loading branch information
Showing
17 changed files
with
209 additions
and
949 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
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
node_modules | ||
coverage | ||
coverage | ||
|
||
*.d.ts | ||
*.js |
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,34 @@ | ||
export class SqlContainer { | ||
public readonly chains: ReadonlyArray<string> | ||
public readonly expressions: any[] | ||
public readonly count: number | ||
constructor( | ||
chains: ReadonlyArray<string>, | ||
expressions: any[], | ||
count: number | ||
) { | ||
this.chains = chains | ||
this.expressions = expressions | ||
this.count = count | ||
} | ||
} | ||
|
||
export type TemplateLiteralFunc<T> = ( | ||
chains: ReadonlyArray<string>, | ||
...expressions: any[] | ||
) => T | ||
|
||
export interface IPGQueryConfig { | ||
_sql?: SqlContainer | ||
text: string | ||
values: any[] | ||
} | ||
|
||
export interface IPGQueryResult { | ||
rowCount: number | ||
rows: any[] | ||
} | ||
|
||
export interface IPGQueryable { | ||
readonly query: (query: IPGQueryConfig) => Promise<IPGQueryResult> | ||
} |
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
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,40 @@ | ||
import { | ||
IPGQueryable, | ||
IPGQueryConfig, | ||
IPGQueryResult, | ||
TemplateLiteralFunc | ||
} from './lib/utils' | ||
import _sql = require('./sql') | ||
|
||
type PGSqlHelper<T> = (db: IPGQueryable) => TemplateLiteralFunc<Promise<T>> | ||
|
||
type PGSql = TemplateLiteralFunc<IPGQueryConfig> & { | ||
query: PGSqlHelper<IPGQueryResult> | ||
many: PGSqlHelper<any[]> | ||
one: PGSqlHelper<any> | ||
count: PGSqlHelper<number> | ||
} | ||
|
||
const sql = ((chains, ...expressions) => _sql(chains, ...expressions)) as PGSql | ||
|
||
sql.query = db => (chains, ...expressions) => | ||
db.query(_sql(chains, ...expressions)) | ||
|
||
sql.one = db => async (chains, ...expressions) => { | ||
const { | ||
rows: [row] | ||
} = await db.query(_sql(chains, ...expressions)) | ||
return row | ||
} | ||
|
||
sql.many = db => async (chains, ...expressions) => { | ||
const { rows } = await db.query(_sql(chains, ...expressions)) | ||
return rows | ||
} | ||
|
||
sql.count = db => async (chains, ...expressions) => { | ||
const { rowCount } = await db.query(_sql(chains, ...expressions)) | ||
return rowCount | ||
} | ||
|
||
export = sql |
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
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
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
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
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,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"declaration": true | ||
}, | ||
"files": ["sql.ts", "pg.ts"] | ||
} |
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 @@ | ||
{ | ||
"extends": ["tslint:recommended", "tslint-config-prettier"], | ||
"rules": { | ||
"variable-name": false | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.