SQLean's uuid4() in SQLite CREATE TABLE

I'm using Turso, enabled SQLean uuid extension and I would like to generate a table via drizzle-kit with a following id:
id: text("id")
.primaryKey()
.default(sql`uuid4()`),
id: text("id")
.primaryKey()
.default(sql`uuid4()`),
and the output:
`id` text PRIMARY KEY DEFAULT uuid4() NOT NULL,
`id` text PRIMARY KEY DEFAULT uuid4() NOT NULL,
If I'm not mistaken, this should be possible but throws an error. Is there any workaround?
S
Sillvva13d ago
I believe it should look like this:
`id` text PRIMARY KEY DEFAULT(uuid4()) NOT NULL
`id` text PRIMARY KEY DEFAULT(uuid4()) NOT NULL
Try this:
id: text("id")
.primaryKey()
.default(sql`DEFAULT(uuid4())`),
id: text("id")
.primaryKey()
.default(sql`DEFAULT(uuid4())`),
P
Pramus13d ago
Unfortunately this results in a broken syntax (note I mistakenly removed one DEFAULT from my initial output, fixed it):
`id` text PRIMARY KEY DEFAULT DEFAULT(uuid4()) NOT NULL,
`id` text PRIMARY KEY DEFAULT DEFAULT(uuid4()) NOT NULL,
AFAIK the syntax for default values is DEFAULT + value rather than DEFAULT(value)
S
Sillvva13d ago
Gotcha. Try this, then:
id: text("id")
.primaryKey()
.default(sql`(uuid4())`),
id: text("id")
.primaryKey()
.default(sql`(uuid4())`),
I had tested both syntaxes DEFAULT func() and DEFAULT(func()) in a sandbox environment. The first threw a syntax error. https://sqliteonline.com/
SQL Online Compiler - Next gen SQL Editor
SQL OnLine - Next gen SQL Editor: SQLite, MariaDB / MySQL, PostgreSQL, MS SQL Server. User-friendly interface for data science. No registration for start, No DownLoad, No Install. Online test SQL script. Online Open/Save SQLite file. Online view all table DB. Fiddle link SQL text and DB file. SQL Test, SQLite in Browser, Data for World, online s...
P
Pramus13d ago
I tried that as well. It parses correctly but creating a new row results in the string literal being inserted into a field but I imagine it's a Turso/SQLite issue rather than Drizzle. In fact the same thing happens in the sandbox you shared. If you create a table with such fields:
`id` text PRIMARY KEY DEFAULT (uuid4()) NOT NULL,
`created_at` text DEFAULT (current_timestamp) NOT NULL
`id` text PRIMARY KEY DEFAULT (uuid4()) NOT NULL,
`created_at` text DEFAULT (current_timestamp) NOT NULL
and then create a row, you'll see that the "uuid4()" and "current_timestamp" are string literals. Strange...
No description
S
Sillvva13d ago
Yeah, that's odd. Not sure then
P
Pramus13d ago
I think I might've figured out what is the problem. Not sure if it exists in code but definitely in Drizzle Studio. I created an issue on GitHub: https://github.com/drizzle-team/drizzle-orm/issues/2198
GitHub
[BUG]: SQLite/Turso libsql: Drizzle (Studio) not running functions ...
What version of drizzle-orm are you using? 0.30.9 What version of drizzle-kit are you using? 0.20.17 Describe the Bug For a following table: export const organizations = sqliteTable( "organiza...
Want results from more Discord servers?
Add your server
More Posts
How can we specify COLLATE on the schema?There is a feature request here: https://github.com/drizzle-team/drizzle-orm/issues/638 For adding Drizzle pg client throwing `scanner_yyerror` on pushGetting the following error upon running `drizzle-kit push:pg` to my local postgres. Drizzle-Kit verDrizzleError: Rollback is being rethrown unexpectedlyNo matter which error I throw for the rollback - it doesn't work as indented because it bleeds outsiId being required in types when using insert and valuesHello! I' been following the tutorial and I'm having a issue with the following function: ```js expoFailed push to planetscaleEvery time I try to push my schema to Planetscale, I get the following error: ``` if (unsquashSelect parent rows where child existsI want to use a relational query to select all users and their posts where users have at least one pCreating a View with Turso/Sqlite```export const jobsView = sqliteView("jobsView").as((qb) => qb .select({ id: job.id, How to update "updated_at" column automaticly when related row is updated?Hello. I'm using PostgreSQL as a dbms. So driver is pg. I want to update the "updated_at" column wwrap migrations in transactiondoes drizzle wrap migrations in transaction?Error with Nested TransactionsI'm experiencing an issue with nested transactions on neon serverless 0.9.1, drizzle-orm 0.30.9, andSupabase branching w/ Drizzle?Does anyone know if it is possible to get Supabase branching working with Drizzle migrations? (httpsType inference is not working when findFirst is extractedHey typescript wizards, could anyone spot what I'm doing wrong here? ```ts type OrgTableQueryParamsDrizzle Query, Relationship Sub-QueryI have Domains and Products, and a pivot between them (DomainProducts). I'd like to query (`findFirMariaDB driver and generate migrationsThe company im working for insists on using MariaDB but im having issues generating migrations for m