Confused by Kysely

I'm using kysely for a project and I'm using it to create tables, however now that I create the tables with the columns and behaviors I want, I need to essentially do the same by writing the typescript type, which seems bad. Am I missing something or is that really how I'm expected to do this?

for example here is a users table


const createUserTable = async () => {
  await db.schema
    .createTable("users")
    .addColumn("id", "integer", (cb) =>
      cb.primaryKey().autoIncrement().notNull()
    )
    .addColumn("email", "varchar(255)", (cb) => cb.notNull().unique())
    .addColumn("password", "varchar(255)", (cb) => cb.notNull())
    .addColumn("is_admin", "boolean", (cb) => cb.notNull().defaultTo(false))
    .addColumn("first_name", "varchar(255)", (cb) => cb.notNull())
    .addColumn("last_name", "varchar(255)")
    .addColumn("created_at", "timestamp", (cb) =>
      cb.notNull().defaultTo(sql`current_timestamp`)
    )
    .addColumn("last_login", "timestamp")
    .execute();
};



Now if I want this to have typescript types I have to write this as well
export interface UsersTable {

  id: Generated<number>;
  email: string;
  password: string;

  is_admin: Generated<0 | 1>;
  first_name: string;
  last_name: string | null;

  created_at: ColumnType<Date, string | undefined, never>;
  last_login: Date | null;
}

export type User = Selectable<UsersTable>;
export type NewUser = Insertable<UsersTable>;
export type UserUpdate = Updateable<UsersTable>;


I would think that the library should be able to auto generate this type from all the information I give it when I create the damn table
Was this page helpful?