Allow passing in db interfaces for insert operations
See original GitHub issueCurrently 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:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Reopened this as I’m working on a POC for this after multiple requests.
There’s some discussion about this idea here