mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
feat(slonik): add types for new API (#36957)
* feat: add types for new API (https://github.com/gajus/slonik/compare/v18.1.1...v18.2.0) * feat: update slonik version * fix: lint errors * test(slonik): add tests for createSqlTag API * test(slonik): fix codestyle
This commit is contained in:
parent
b7c4682214
commit
26fcfa878e
10
types/slonik/index.d.ts
vendored
10
types/slonik/index.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// Type definitions for slonik 16.16
|
||||
// Type definitions for slonik 18.2
|
||||
// Project: https://github.com/gajus/slonik#readme
|
||||
// Definitions by: Sebastian Sebald <https://github.com/sebald>
|
||||
// Misha Kaletsky <https://github.com/mmkal>
|
||||
@ -292,6 +292,14 @@ export interface TaggedTemplateLiteralInvocationType<Result = QueryResultRowType
|
||||
|
||||
export const sql: SqlTaggedTemplateType;
|
||||
|
||||
export type IdentifierNormalizerType = (identifierName: string) => string;
|
||||
|
||||
export interface SqlTagConfigurationType {
|
||||
normalizeIdentifier?: IdentifierNormalizerType;
|
||||
}
|
||||
|
||||
export function createSqlTag(configuration?: SqlTagConfigurationType): SqlTaggedTemplateType;
|
||||
|
||||
export interface SqlTaggedTemplateType {
|
||||
// tslint:disable-next-line no-unnecessary-generics (the sql<Foo>`select foo` is cleaner in this case than casting with 'as')
|
||||
<T = QueryResultRowType>(template: TemplateStringsArray, ...vals: ValueExpressionType[]): SqlSqlTokenType<T>;
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import {
|
||||
createSqlTag,
|
||||
IdentifierNormalizerType,
|
||||
CheckIntegrityConstraintViolationError,
|
||||
createBenchmarkingInterceptor,
|
||||
createBigintTypeParser,
|
||||
@ -22,7 +24,8 @@ import {
|
||||
SlonikError,
|
||||
sql,
|
||||
TypeParserType,
|
||||
UniqueIntegrityConstraintViolationError
|
||||
UniqueIntegrityConstraintViolationError,
|
||||
SqlTaggedTemplateType
|
||||
} from 'slonik';
|
||||
import { ArrayTokenSymbol, TupleListTokenSymbol } from 'slonik/symbols';
|
||||
|
||||
@ -326,6 +329,33 @@ createTimestampWithTimeZoneTypeParser();
|
||||
`;
|
||||
})();
|
||||
|
||||
//
|
||||
// createSQLTag
|
||||
// ----------------------------------------------------------------------
|
||||
(() => {
|
||||
let sql: SqlTaggedTemplateType;
|
||||
|
||||
sql = createSqlTag();
|
||||
|
||||
sql`
|
||||
SELECT 1;
|
||||
`;
|
||||
|
||||
let normalizeIdentifier: IdentifierNormalizerType;
|
||||
|
||||
normalizeIdentifier = (input: string) =>
|
||||
input
|
||||
.split('')
|
||||
.reverse()
|
||||
.join('');
|
||||
|
||||
sql = createSqlTag({
|
||||
normalizeIdentifier,
|
||||
});
|
||||
|
||||
sql = createSqlTag({});
|
||||
});
|
||||
|
||||
//
|
||||
// ERRORS
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user