-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:cesumilo/Denobjection into develop
- Loading branch information
Showing
28 changed files
with
3,568 additions
and
1,577 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 |
---|---|---|
|
@@ -29,5 +29,9 @@ | |
"include": [ | ||
"./tests" | ||
] | ||
}, | ||
"compilerOptions": { | ||
"experimentalDecorators": true, | ||
"noImplicitOverride": true | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
import { normalizeRawArgs, RawBuilder } from './RawBuilder.ts'; | ||
import { asSingle, isNumber } from '../utils/object.ts'; | ||
import { nany } from '../ninja.ts'; | ||
|
||
class FunctionBuilder extends RawBuilder {} | ||
|
||
const keywords = [ | ||
'coalesce', | ||
'concat', | ||
'sum', | ||
'avg', | ||
'min', | ||
'max', | ||
'count', | ||
'upper', | ||
'lower', | ||
// deno-lint-ignore no-explicit-any | ||
].reduce((c: any, p: string) => { | ||
c[p] = true; | ||
return c; | ||
}, {}); | ||
|
||
function fn(...argsIn: [string, ...nany[]]) { | ||
const { sql, args } = normalizeRawArgs(argsIn); | ||
return new FunctionBuilder(`${sql}(${args.map(() => '?').join(', ')})`, args); | ||
} | ||
|
||
export function createFunctionBuilder( | ||
name: string, | ||
): (...args: nany[]) => FunctionBuilder { | ||
if (name === 'now') { | ||
return (precision: string | string[]) => { | ||
let p = parseInt(asSingle(precision), 10); | ||
|
||
if (isNaN(p) || !isNumber(p)) { | ||
p = 6; | ||
} | ||
|
||
// We need to use a literal precision instead of a binding here | ||
// for the CURRENT_TIMESTAMP to work. This is okay here since we | ||
// make sure `precision` is a number. There's no chance of SQL | ||
// injection here. | ||
return new FunctionBuilder(`CURRENT_TIMESTAMP(${p})`, []); | ||
}; | ||
} else if (keywords[name]) { | ||
return (...args: nany[]) => fn(name, args); | ||
} | ||
throw new Error(`Function ${name} not supported.`); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.