drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Option to create dynamic tables

Open
#5,696 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Feature hasn't been suggested before.

- [x] I have verified this feature I'm about to request hasn't been suggested before.

### Describe the enhancement you want to request

It would be great to have an option to manage tables in the database at runtime, not just through migrations.

For example:
```ts
const tableFactory = (name: string) =>
sqliteTable(name, {
id: integer({ mode: "number" }).primaryKey({ autoIncrement: true }),
....other columns
});

await tableFactory("some_table").createIfNotExists()
```

Or at least an option to generate SQL from this:
```ts
const tableFactory = (name: string) =>
sqliteTable(name, {
id: integer({ mode: "number" }).primaryKey({ autoIncrement: true }),
....other columns
});

const sql = tableFactory("some_table").getSQL()

await db.$client.execute(sql);
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing the sqliteTable factory and the database $client.execute path mentioned in the examples. Determine whether runtime table creation or SQL generation is the intended scope, then define how dynamic table names and columns should be represented. Done means one supported API works at runtime with appropriate verification for the generated or executed table definition.

Written by the indexing model from the issue text.

Assessment

Tech stack
sqlite, typescript
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.