cosbgn
cosbgn
Explore posts from servers
DTDrizzle Team
Created by cosbgn on 7/5/2024 in #help
D1_ERROR: near "in": syntax error at offset 153
Wrong table - don't mind me
2 replies
DTDrizzle Team
Created by Gabriel Lucena on 5/31/2024 in #help
Help querying D1 with Drizzle
I guess you could apply migrations with drizzle for the production env, but it won't work for the local one, so you might as well stick with wrangler which will work for both.
9 replies
DTDrizzle Team
Created by Gabriel Lucena on 5/31/2024 in #help
Help querying D1 with Drizzle
So for anyone trying d1, this is what I suggest: 1st: d1-http for drizzle.config.js (migrations & studio)
export default {
dialect:"sqlite",
driver:"d1-http",
schema: "server/db/schema.js",
out: "server/db/migrations",
dbCredentials: {
accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
databaseId: process.env.CLOUDFLARE_D1_ID,
token: process.env.CLOUDFLARE_D1_TOKEN,
}
}
export default {
dialect:"sqlite",
driver:"d1-http",
schema: "server/db/schema.js",
out: "server/db/migrations",
dbCredentials: {
accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
databaseId: process.env.CLOUDFLARE_D1_ID,
token: process.env.CLOUDFLARE_D1_TOKEN,
}
}
2nd: Binding for drizzle orm, you need to figure out how to use bindings locally, most frameworks have a way:
import { drizzle } from 'drizzle-orm/d1';
drizzle(event.context.cloudflare.env.DB, { schema: schema_file })
import { drizzle } from 'drizzle-orm/d1';
drizzle(event.context.cloudflare.env.DB, { schema: schema_file })
To migrate use:
drizzle-kit generate // generate migration files
npx wrangler d1 migrations apply db_name --local
drizzle-kit generate // generate migration files
npx wrangler d1 migrations apply db_name --local
use --local for local and --remote for the production db
9 replies
DTDrizzle Team
Created by Gabriel Lucena on 5/31/2024 in #help
Help querying D1 with Drizzle
To be fair, this is more a cloudflare issue rather than drizzle. If cloudflare would provide a simple http endpoins like turso it would work as easily. The problem is that they use binding so it's complicated and everyone has a different way to use bindings locally. I think the current setup is almost perfect, binding for drizzle orm and d1-http for studio/migrations. You get best of both worlds. The only thing missing really is studio & migrations against the local db. For migrations I use wrangler (for both local and prod) and for studio I use a vscode extension which shows me a studio-link table when I click on the local db.
9 replies
DTDrizzle Team
Created by Gabriel Lucena on 5/31/2024 in #help
Help querying D1 with Drizzle
Would be cool if there would be a driver which would use binding and fallback to proxy. It would work in both dev and production perfectly with minimal config.
9 replies
DTDrizzle Team
Created by cosbgn on 3/13/2024 in #help
How do I mark "migration as applied" after using "push"?
Thanks
10 replies
DTDrizzle Team
Created by cosbgn on 3/13/2024 in #help
How do I mark "migration as applied" after using "push"?
sqlite/turso
10 replies
DTDrizzle Team
Created by cosbgn on 3/13/2024 in #help
How do I mark "migration as applied" after using "push"?
Also, with generate will drizzle understand/know different databases (e.g. production vs local) or should I add the whole /migrations folder on .gitignore
10 replies
DTDrizzle Team
Created by cosbgn on 3/13/2024 in #help
How do I mark "migration as applied" after using "push"?
now I want to switch to generate
10 replies
DTDrizzle Team
Created by cosbgn on 3/13/2024 in #help
How do I mark "migration as applied" after using "push"?
So I used drizzle-kit push for a while since I had to do a lot of migrations
10 replies
DTDrizzle Team
Created by Morten on 8/28/2023 in #help
is there any way to create related records with the main record together like this in prisma
is this featured planned? e.g. create/edit/delete with relational queries
8 replies
DTDrizzle Team
Created by cosbgn on 8/9/2023 in #help
Why {unique:true} doesn't throw?
Great, thanks
5 replies
DTDrizzle Team
Created by cosbgn on 7/13/2023 in #help
connect to local postgres
3 replies
DTDrizzle Team
Created by cosbgn on 6/7/2023 in #help
Relational queries for editing?
relational queries are so much cleaner
6 replies
DTDrizzle Team
Created by cosbgn on 6/7/2023 in #help
Relational queries for editing?
The main issue for me is the need to import { eq, lt, gte, ne } and models everywhere, it get's messy
6 replies
DTDrizzle Team
Created by cosbgn on 6/7/2023 in #help
Relational queries for editing?
Are relational queries planned for things like update/delete/add or they will always be just for reading data?
6 replies