question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow passing in db interfaces for insert operations

See original GitHub issue

Currently Kysely relies on the user passing in db.generated when inserting not null columns with default values since it only knows these columns are not null. If we could pass in separate interfaces for insert operations this process would be more type-safe.

Here’s an idea for the api

interface Person {
  id: number
  first_name: string
  last_name: string
  gender: 'male' | 'female' | 'other'
}

interface Database {
  person: Person
}

interface InsertablePerson {
  // id is generated as identity
  id?: number
  first_name: string
  last_name: string
  gender: 'male' | 'female' | 'other'
}

interface InsertableDatabase {
  person: InsertablePerson
}

// Insertable interfaces are passed to the second type param.
const db = new Kysely<Database, InsertableDatabase>({
  dialect: new PostgresDialect({
    host: 'localhost',
    database: 'kysely_test',
  })
})

Some libraries that generate db table interfaces, for example kanel, also generate interfaces for insert operations, which accounts for generated values. It’d be very much useful if we could pass those interfaces to Kysely.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
koskimascommented, Jan 2, 2022

Reopened this as I’m working on a POC for this after multiple requests.

1reaction
koskimascommented, Nov 18, 2021

There’s some discussion about this idea here

Read more comments on GitHub >

github_iconTop Results From Across the Web

20 Data Interface for Persistent LOBs
To perform piecewise INSERT or UPDATE operations with callback using the data interface for persistent LOBs, do the following steps: Call OCIStmtPrepare() to ......
Read more >
Performing Database Operations in Java | SQL CREATE ...
These basic operations are INSERT, SELECT, UPDATE and DELETE statements in ... Let's take an overview look at the JDBC's main interfaces and ......
Read more >
Pointer Passing Interfaces - SQLite
Passing around pointers as if they were integers or BLOBs is easy, effective, and works well in an environment where the application components ......
Read more >
Java JDBC CRUD Tutorial: SQL Insert, Select, Update, and ...
This JDBC tutorial is going to help you learning how to do basic database operations (CRUD - Create, Retrieve, Update and Delete) using...
Read more >
Accessing data using Room DAOs - Android Developers
Anatomy of a DAO · Convenience methods that let you insert, update, and delete rows in your database without writing any SQL code....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found