kysely icon indicating copy to clipboard operation
kysely copied to clipboard

Add `CREATE TABLE ... LIKE ...` syntax

Open ClayenKitten opened this issue 1 year ago • 0 comments

CREATE TABLE newTableName LIKE templateTableName allows creating the table with the same structure as an already existing one, and is especially useful when creating temporary tables.

It is supported by PostgreSQL and MySQL.

I suggest the following syntax:

await db.createTable("newTable")
    .like("oldTable")
    .including("INDEXES"); // Only for PostgreSQL.
    .including("COMMENTS") // User may specify multiple including statements, maybe we should use accept array as parameter instead?
    .excluding("DEFAULTS") // Excluding is the default, but can be useful with `.including("ALL")`.
    // ...

I may look into implementing that, if that feature would be accepted into the project. Thanks in advance!

ClayenKitten avatar Oct 19 '24 21:10 ClayenKitten