* chore: tests for slonik 19

* feat: slonik 19
This commit is contained in:
Misha Kaletsky
2019-09-25 17:32:34 -04:00
committed by Michael Crane
parent 63e8585f24
commit 308e471106
2 changed files with 6 additions and 208 deletions

View File

@@ -1,4 +1,4 @@
// Type definitions for slonik 18.6
// Type definitions for slonik 19.0
// Project: https://github.com/gajus/slonik#readme
// Definitions by: Sebastian Sebald <https://github.com/sebald>
// Misha Kaletsky <https://github.com/mmkal>
@@ -47,16 +47,6 @@ export interface IdentifierTokenType {
type: typeof SlonikSymbol.IdentifierTokenSymbol;
}
export type IdentifierListMemberType = string[] | {
alias: string
identifier: string[]
};
export interface IdentifierListTokenType {
identifiers: IdentifierListMemberType[];
type: typeof SlonikSymbol.IdentifierListTokenSymbol;
}
export type SqlSqlTokenType<T> = TaggedTemplateLiteralInvocationType<T>;
export interface RawSqlTokenType {
@@ -65,11 +55,6 @@ export interface RawSqlTokenType {
values: PrimitiveValueExpressionType[];
}
export interface ValueListSqlTokenType {
values: PrimitiveValueExpressionType[];
type: typeof SlonikSymbol.ValueListTokenSymbol;
}
export interface ArraySqlTokenType {
memberType: string;
type: typeof SlonikSymbol.ArrayTokenSymbol;
@@ -81,56 +66,21 @@ export interface JsonSqlTokenType {
type: typeof SlonikSymbol.JsonTokenSymbol;
}
export interface TupleSqlTokenType {
values: PrimitiveValueExpressionType[];
type: typeof SlonikSymbol.TupleTokenSymbol;
}
export interface TupleListSqlTokenType {
tuples: PrimitiveValueExpressionType[];
type: typeof SlonikSymbol.TupleListTokenSymbol;
}
export interface UnnestSqlTokenType {
columnTypes: string[];
tuples: PrimitiveValueExpressionType[][];
type: typeof SlonikSymbol.UnnestTokenSymbol;
}
export interface ComparisonPredicateTokenType {
leftOperand: ValueExpressionType;
operator: ComparisonOperatorType;
rightOperand: ValueExpressionType;
type: typeof SlonikSymbol.ComparisonPredicateTokenSymbol;
}
export interface BooleanExpressionTokenType {
members: ValueExpressionType[];
operator: LogicalBooleanOperatorType;
type: typeof SlonikSymbol.ComparisonPredicateTokenSymbol;
}
export interface AssignmentListTokenType {
namedAssignment: NamedAssignmentType;
type: typeof SlonikSymbol.ComparisonPredicateTokenSymbol;
}
export type PrimitiveValueExpressionType = string | number | boolean | null;
export type SqlTokenType =
ArraySqlTokenType |
AssignmentListTokenType |
IdentifierTokenType |
IdentifierListTokenType |
JsonSqlTokenType |
RawSqlTokenType |
SqlSqlTokenType<any> |
TupleListSqlTokenType |
TupleSqlTokenType |
UnnestSqlTokenType |
ValueListSqlTokenType |
ComparisonPredicateTokenType |
BooleanExpressionTokenType;
UnnestSqlTokenType;
export type ValueExpressionType =
SqlTokenType |
@@ -329,24 +279,9 @@ export interface SqlTaggedTemplateType {
values: PrimitiveValueExpressionType[],
memberType: string
) => ArraySqlTokenType;
assignmentList: (
namedAssignmentValueBindings: NamedAssignmentType
) => AssignmentListTokenType;
booleanExpression: (
members: ValueExpressionType[],
operator: LogicalBooleanOperatorType
) => BooleanExpressionTokenType;
comparisonPredicate: (
leftOperand: ValueExpressionType,
operator: ComparisonOperatorType,
rightOperand: ValueExpressionType
) => ComparisonPredicateTokenType;
identifier: (
names: string[]
) => IdentifierTokenType;
identifierList: (
identifiers: IdentifierListMemberType[]
) => IdentifierListTokenType;
json: (
value: SerializableValueType
) => JsonSqlTokenType;
@@ -354,12 +289,6 @@ export interface SqlTaggedTemplateType {
rawSql: string,
values?: PrimitiveValueExpressionType[]
) => RawSqlTokenType;
tuple: (
values: ValueExpressionType[]
) => TupleSqlTokenType;
tupleList: (
tuples: ValueExpressionType[][]
) => TupleListSqlTokenType;
unnest: (
// Value might be PrimitiveValueExpressionType[],
// or it can be infinitely nested array, e.g.
@@ -367,9 +296,6 @@ export interface SqlTaggedTemplateType {
tuples: any[][],
columnTypes: string[]
) => UnnestSqlTokenType;
valueList: (
values: ValueExpressionType[]
) => ValueListSqlTokenType;
}
export interface SqlFragmentType {

View File

@@ -10,15 +10,10 @@ import {
createQueryNormalizationInterceptor,
createTimestampTypeParser,
createTimestampWithTimeZoneTypeParser,
DatabaseConnectionType,
DatabasePoolConnectionType,
DatabasePoolType,
DatabaseTransactionConnectionType,
createTypeParserPreset,
DataIntegrityError,
ForeignKeyIntegrityConstraintViolationError,
IntegrityConstraintViolationError,
InterceptorType,
NotFoundError,
NotNullIntegrityConstraintViolationError,
SlonikError,
@@ -211,16 +206,6 @@ createTimestampWithTimeZoneTypeParser();
//
// RECIPES
// ----------------------------------------------------------------------
(async () => {
await connection.query(sql`
INSERT INTO (foo, bar, baz)
VALUES ${sql.tupleList([
[1, 2, 3],
[4, 5, 6]
])}
`);
})();
(async () => {
await connection.query(sql`
INSERT INTO (foo, bar, baz)
@@ -310,23 +295,6 @@ createTimestampWithTimeZoneTypeParser();
// $ExpectError
sql`SELECT ${sql.json(undefined)}`;
await connection.query(sql`
SELECT (${sql.valueList([1, 2, 3])})
`);
await connection.query(sql`
INSERT INTO (foo, bar, baz)
VALUES ${sql.tuple([1, 2, 3])}
`);
await connection.query(sql`
INSERT INTO (foo, bar, baz)
VALUES ${sql.tupleList([
[1, 2, 3],
[4, 5, 6]
])}
`);
await connection.query(sql`
SELECT bar, baz
FROM ${sql.unnest(
@@ -399,26 +367,6 @@ const samplesFromDocs = async () => {
// some samples generated by parsing the readme from slonik's github page
// start samples from readme
const sample1 = async () => {
connection.query(sql`
SELECT ${sql.identifier(['foo', 'a'])}
FROM (
VALUES ${sql.tupleList([['a1', 'b1', 'c1'], ['a2', 'b2', 'c2']])}
) foo(a, b, c)
WHERE foo.b IN (${sql.valueList(['c1', 'a2'])})
`);
};
const sample2 = async () => {
await connection.query(sql`
INSERT INTO (foo, bar, baz)
VALUES ${sql.tupleList([
[1, 2, 3],
[4, 5, 6]
])}
`);
};
const sample3 = async () => {
await connection.query(sql`
INSERT INTO (foo, bar, baz)
SELECT *
@@ -436,46 +384,18 @@ const samplesFromDocs = async () => {
`);
};
const sample4 = async () => {
await connection.query(sql`
SELECT (${sql.valueList([1, 2, 3])})
`);
};
const sample5 = async () => {
const sample2 = async () => {
await connection.query(sql`
SELECT (${sql.array([1, 2, 3], 'int4')})
`);
};
const sample6 = async () => {
sql`SELECT id FROM foo WHERE id IN (${sql.valueList([1, 2, 3])})`;
sql`SELECT id FROM foo WHERE id NOT IN (${sql.valueList([1, 2, 3])})`;
};
const sample7 = async () => {
const sample3 = async () => {
sql`SELECT id FROM foo WHERE id = ANY(${sql.array([1, 2, 3], 'int4')})`;
sql`SELECT id FROM foo WHERE id != ALL(${sql.array([1, 2, 3], 'int4')})`;
};
const sample8 = async () => {
await connection.query(sql`
INSERT INTO (foo, bar, baz)
VALUES ${sql.tuple([1, 2, 3])}
`);
};
const sample9 = async () => {
await connection.query(sql`
INSERT INTO (foo, bar, baz)
VALUES ${sql.tupleList([
[1, 2, 3],
[4, 5, 6]
])}
`);
};
const sample10 = async () => {
const sample4 = async () => {
await connection.query(sql`
SELECT bar, baz
FROM ${sql.unnest(
@@ -491,59 +411,11 @@ const samplesFromDocs = async () => {
`);
};
const sample11 = async () => {
const sample5 = async () => {
sql`
SELECT 1
FROM ${sql.identifier(['bar', 'baz'])}
`;
};
const sample12 = async () => {
sql`
SELECT 1
FROM ${sql.identifierList([
['bar', 'baz'],
['qux', 'quux']
])}
`;
};
const sample13 = async () => {
sql`
SELECT 1
FROM ${sql.identifierList([
{
alias: 'qux',
identifier: ['bar', 'baz']
},
{
alias: 'corge',
identifier: ['quux', 'quuz']
}
])}
`;
};
const sample14 = async () => {
sql`
SELECT ${sql.booleanExpression([3, 4], 'AND')}
`;
};
const sample15 = async () => {
sql`
SELECT ${sql.comparisonPredicate(3, '=', 4)}
`;
};
const sample16 = async () => {
await connection.query(sql`
UPDATE foo
SET ${sql.assignmentList({
bar: 'baz',
qux: 'quux'
})}
`);
};
// end samples from readme
};