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:
Laurin Quast 2019-07-18 21:02:52 +02:00 committed by Andrew Branch
parent b7c4682214
commit 26fcfa878e
2 changed files with 40 additions and 2 deletions

View File

@ -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>;

View File

@ -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
// ----------------------------------------------------------------------