Kysely-tables allows developers to use Kysely types as the single source of truth for database schema, migrations, and queries. This approach eliminates the need for complex intermediary APIs and enhances type safety while efficiently generating SQL schemas. Ideal for those looking to simplify their database handling in modern applications.
The kysely-tables project provides a unified approach to managing SQL databases by utilizing the same Kysely types for defining your table schema, executing migrations, and processing queries. This innovative solution eliminates the need for intermediary schema-defining APIs or languages, streamlining the development process.
CREATE TABLE statements. This ensures consistency across your database schema, migrations, and queries.The project focuses on an innovative use of annotation types that enhance standard Kysely types while maintaining their original capabilities. These annotations work in conjunction with a processing tool to automatically generate SQL schemas and migrations by analyzing schema changes.
To use this library, inspect the db.ts file in the examples for a clear picture of how table definitions align with Kysely's expectations. For example:
export interface UsersTable {
id: Generated<Primary<number>>
name: Sized<string, 100> | null
email: Unique<Sized<string, 255>>
passwordHash: Text<string>
role: Default<string, "'member'">
createdAt: Default<Date, 'now()'>
updatedAt: Default<Date, 'now()'>
deletedAt: null | Date
}
In this setup, types such as Generated, Primary, and Unique are fully compatible with Kysely and facilitate efficient schema generation.
The migration process is intuitive—simply modify the db.ts file to reflect changes and run a command to generate a new migration.
% tsx db.ts --revision
This operation outputs migration files which can be executed to keep your database schema in sync with your application logic.
Built with simplicity in mind, kysely-tables offers a lightweight yet effective architecture that inspires confidence in database management. Those interested in contributing to the project are encouraged to report bugs and suggest features.
For further details, please refer to the comprehensive blog post associated with the project.
No comments yet.
Sign in to be the first to comment.