diff --git a/types/slonik/index.d.ts b/types/slonik/index.d.ts index 7f0e7c6d82..336386f9e1 100644 --- a/types/slonik/index.d.ts +++ b/types/slonik/index.d.ts @@ -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 // Misha Kaletsky @@ -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 = TaggedTemplateLiteralInvocationType; 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 | - 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 { diff --git a/types/slonik/slonik-tests.ts b/types/slonik/slonik-tests.ts index 3efcced500..f4d448b4df 100644 --- a/types/slonik/slonik-tests.ts +++ b/types/slonik/slonik-tests.ts @@ -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 };