Skip to content

Commit

Permalink
fix all tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
igalklebanov committed Jan 5, 2025
1 parent a6caf96 commit caf92cc
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/query-builder/function-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
* ```
*/
max<
O extends number | bigint | Date | string | null = never,
O extends number | string | Date | bigint | null = never,
RE extends ReferenceExpression<DB, TB> = ReferenceExpression<DB, TB>,
>(
expr: RE,
Expand All @@ -499,7 +499,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
DB,
TB,
RE,
number | bigint | Date | string
number | string | Date | bigint
>
: O
>
Expand Down Expand Up @@ -543,7 +543,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
* ```
*/
min<
O extends number | bigint | Date | string | null = never,
O extends number | string | Date | bigint | null = never,
RE extends ReferenceExpression<DB, TB> = ReferenceExpression<DB, TB>,
>(
expr: RE,
Expand All @@ -555,7 +555,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
DB,
TB,
RE,
number | bigint | Date | string
number | string | Date | bigint
>
: O
>
Expand Down
34 changes: 34 additions & 0 deletions test/node/src/introspect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ for (const dialect of DIALECTS) {
hasDefaultValue: true,
comment: undefined,
},
{
name: 'created_at',
dataType: 'timestamptz',
dataTypeSchema: 'pg_catalog',
isNullable: false,
isAutoIncrementing: false,
hasDefaultValue: true,
comment: undefined,
},
],
},
{
Expand Down Expand Up @@ -361,6 +370,14 @@ for (const dialect of DIALECTS) {
hasDefaultValue: true,
comment: undefined,
},
{
name: 'created_at',
dataType: 'datetime',
isNullable: false,
isAutoIncrementing: false,
hasDefaultValue: true,
comment: undefined,
},
],
},
{
Expand Down Expand Up @@ -473,6 +490,15 @@ for (const dialect of DIALECTS) {
name: 'children',
comment: undefined,
},
{
dataType: 'datetime',
dataTypeSchema: 'sys',
hasDefaultValue: true,
isAutoIncrementing: false,
isNullable: false,
name: 'created_at',
comment: undefined,
},
{
dataType: 'varchar',
dataTypeSchema: 'sys',
Expand Down Expand Up @@ -720,6 +746,14 @@ for (const dialect of DIALECTS) {
hasDefaultValue: true,
comment: undefined,
},
{
name: 'created_at',
dataType: 'TEXT',
isNullable: false,
isAutoIncrementing: false,
hasDefaultValue: true,
comment: undefined,
},
],
},
{
Expand Down
16 changes: 15 additions & 1 deletion test/node/src/test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ import {
InsertResult,
SqliteDialect,
InsertQueryBuilder,
Logger,
Generated,
sql,
ColumnType,
InsertObject,
MssqlDialect,
SelectQueryBuilder,
GeneratedAlways,
ColumnDataType,
} from '../../../'
import {
OrderByDirection,
Expand All @@ -55,6 +56,7 @@ export interface Person {
gender: Gender
marital_status: MaritalStatus | null
children: Generated<number>
created_at: GeneratedAlways<Date | string>
}

export interface Pet {
Expand Down Expand Up @@ -313,6 +315,18 @@ async function createDatabase(
.addColumn('gender', 'varchar(50)', (col) => col.notNull())
.addColumn('marital_status', 'varchar(50)')
.addColumn('children', 'integer', (col) => col.notNull().defaultTo(0))
.addColumn(
'created_at',
(
{
postgres: 'timestamptz',
mysql: 'datetime',
mssql: 'datetime',
sqlite: 'text',
} satisfies Record<BuiltInDialect, ColumnDataType>
)[dialect],
(col) => col.notNull().defaultTo(sql`current_timestamp`),
)
.execute()

await createTableWithId(db.schema, dialect, 'pet')
Expand Down
4 changes: 2 additions & 2 deletions test/typings/test-d/aggregate-function.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,13 @@ async function testSelectWithDynamicReference(db: Kysely<Database>) {
expectNotAssignable<null>(result.count)
expectAssignable<bigint>(result.another_count)
expectNotAssignable<string | number | null>(result.another_count)
expectAssignable<string | number | bigint>(result.max)
expectAssignable<number | string | Date | bigint>(result.max)
expectNotAssignable<null>(result.max)
expectAssignable<number>(result.another_max)
expectNotAssignable<string | bigint>(result.another_max)
expectAssignable<number | null>(result.nullable_max)
expectNotAssignable<string | bigint>(result.nullable_max)
expectAssignable<string | number | bigint>(result.min)
expectAssignable<number | string | Date | bigint>(result.min)
expectNotAssignable<null>(result.min)
expectAssignable<string>(result.another_min)
expectNotAssignable<number | bigint | null>(result.another_min)
Expand Down

0 comments on commit caf92cc

Please sign in to comment.