Skip to content

Commit

Permalink
fixes #832
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed Jan 5, 2024
1 parent 6b1ab66 commit e034c0e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
6 changes: 0 additions & 6 deletions src/query-builder/insert-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,6 @@ export class InsertQueryBuilder<DB, TB extends keyof DB, O>
* }))
* ```
*/
values(insert: InsertObjectOrList<DB, TB>): InsertQueryBuilder<DB, TB, O>

values(
insert: InsertObjectOrListFactory<DB, TB>
): InsertQueryBuilder<DB, TB, O>

values(insert: InsertExpression<DB, TB>): InsertQueryBuilder<DB, TB, O> {
const [columns, values] = parseInsertExpression(insert)

Expand Down
4 changes: 1 addition & 3 deletions src/query-builder/update-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,8 @@ export class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyof DB, O>
* where "id" = $5
* ```
*/
set(update: UpdateObject<DB, TB, UT>): UpdateQueryBuilder<DB, UT, TB, O>

set(
update: UpdateObjectFactory<DB, TB, UT>
update: UpdateObjectExpression<DB, TB, UT>
): UpdateQueryBuilder<DB, UT, TB, O>

set<RE extends ReferenceExpression<DB, UT>>(
Expand Down
11 changes: 11 additions & 0 deletions test/typings/test-d/insert.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ async function testInsert(db: Kysely<Database>) {

expectType<InsertResult>(r5)

const r6 = await db
.insertInto('person')
.values((eb) => ({
first_name: 'fname',
age: 10,
gender: eb.ref('gender'),
}))
.executeTakeFirst()

expectType<InsertResult>(r6)

// Non-existent table
expectError(db.insertInto('doesnt_exists'))

Expand Down
45 changes: 44 additions & 1 deletion test/typings/test-d/kysely-any.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { DeleteResult, Kysely, UpdateResult } from '..'
import {
DeleteResult,
InsertResult,
Kysely,
UpdateResult,
expressionBuilder,
} from '..'
import { expectType } from 'tsd'

async function testKyselyAnySelects(db: Kysely<any>) {
Expand Down Expand Up @@ -50,6 +56,34 @@ async function testKyselyAnySelects(db: Kysely<any>) {
>(r5)
}

async function testKyselyAnyInserts(db: Kysely<any>) {
const r1 = await db
.insertInto('foo')
.values({ bar: 'baz', spam: 1 })
.executeTakeFirstOrThrow()
expectType<InsertResult>(r1)

const r2 = await db
.insertInto('foo')
.values({ bar: 'baz', spam: 1 })
.returning('foo')
.executeTakeFirstOrThrow()
expectType<{ foo: any }>(r2)

const r3 = await db
.insertInto('foo')
.values({ bar: 'baz', spam: 1 })
.returning(['foo', 'baz'])
.executeTakeFirstOrThrow()
expectType<{ foo: any; baz: any }>(r3)

const r4 = await db
.insertInto('foo')
.values((eb) => ({ foo: eb.ref('foo.bar') }))
.executeTakeFirstOrThrow()
expectType<InsertResult>(r4)
}

async function testKyselyAnyUpdates(db: Kysely<any>) {
const r1 = await db
.updateTable('foo')
Expand All @@ -74,6 +108,15 @@ async function testKyselyAnyUpdates(db: Kysely<any>) {
.returning(['a', 'b'])
.executeTakeFirstOrThrow()
expectType<{ a: any; b: any }>(r3)

const r4 = await db
.updateTable('foo')
.set((eb) => ({
foo: eb('foo.bar', '=', 1),
}))
.where('foo.eggs', '=', 1)
.executeTakeFirstOrThrow()
expectType<UpdateResult>(r4)
}

async function testKyselyAnyDeletes(db: Kysely<any>) {
Expand Down

1 comment on commit e034c0e

@vercel
Copy link

@vercel vercel bot commented on e034c0e Jan 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kysely – ./

kysely.dev
kysely-kysely-team.vercel.app
kysely-git-master-kysely-team.vercel.app
www.kysely.dev

Please sign in to comment.