Is it possible to define a table in an scoped module / file / folder during runtime? i.e. we want to prototype a module that relies on a custom table, but we don't want to populate yet our astro:db with our custom table. We just want to be able to perform operations within said file. Consider that the table already exists, we just want to be able to call astro db with a custom table without defining it into the setup function
#astro db define table on rutime
7 messages · Page 1 of 1 (latest)
Hi @visual copper. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
I'm sorry, but the knowledge sources do not provide information about defining Astro DB tables at runtime or within a scoped module/file/folder without registering them in your main Astro DB config (e.g., db/config.ts). All official documentation describes table definitions as static, requiring you to declare tables in db/config.ts for Astro to generate types and allow operations on those tables. There is no mention of a supported way to dynamically define or reference tables solely within a module at runtime, even if the table already exists in the database.
If you are building an integration, there is a utility called asDrizzleTable() that allows you to create a type-safe table reference for use in integration code, but this still relies on a static table definition (typically in a config file) and is not a runtime table definition mechanism. It is intended for integration development, not for ad-hoc or runtime table creation or referencing outside the main config setup Building Astro DB integrations.
In summary, based on the available documentation, defining tables at runtime or in a local module without registering them in the main Astro DB config is not supported.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@visual copper Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@urban olive is it possible to access the drizzle constructor to create an own drizzle instance to perform custom operations?
Let me check the knowledge base for you again. One moment! :books:
I'm sorry, but the knowledge sources do not provide any information about accessing the Drizzle constructor directly or creating your own Drizzle instance within an Astro project. The documentation only describes using the built-in, pre-configured Drizzle ORM client via the db object imported from astro:db, and does not mention exposing the underlying Drizzle constructor or allowing custom instantiation for advanced or custom operations Query your database.