rphlmr ⚡
DTDrizzle Team
•Created by Tim on 12/12/2024 in #help
Can't seem to $count in multi relation query
Hello, we can do that: https://drizzle.run/kpgllszcgopqrx623i79ca4h
That's not pretty but it works 😬
8 replies
DTDrizzle Team
•Created by Cory on 1/17/2025 in #help
Place relations into seperate file?
Looks like you import “.js” files here. Is it expected?
2 replies
DTDrizzle Team
•Created by brizzle on 1/17/2025 in #help
Pull from an existing schema, but skip in migrations?
👋
The easiest way is to manually create a “keycloak” schema, then a table linked to this schema and just add columns you want to use.
Do not export them from your schema.ts so they will not be part of any migration.
This is how I did for Supabase (before it was built in to Drizzle): https://github.com/rphlmr/drizzle-lab/blob/main/apps/drizzle-run/app/database/.server/schema.ts#L18-L22
2 replies
DTDrizzle Team
•Created by Haaxor1689 on 7/27/2024 in #help
sqlite create new db file push programatically
Import from “drizzle-kit/api” 🚀
6 replies
DTDrizzle Team
•Created by Haaxor1689 on 7/27/2024 in #help
sqlite create new db file push programatically
6 replies
DTDrizzle Team
•Created by uber on 1/10/2025 in #help
🚨 Issue: Testing with PostgreSQL and Drizzle ORM using Testcontainers
Maybe this can help you? https://github.com/rphlmr/drizzle-vitest-pg
7 replies
DTDrizzle Team
•Created by k on 7/31/2024 in #help
Visualize database schema (ERM preferably) when using planetscale with out foreign keys
Thank you 🙏
I can work on that #drizzle-lab now that all the code has been open sourced
15 replies
DTDrizzle Team
•Created by lolmaus (Andrey Mikhaylov) on 10/27/2023 in #help
Acceptance testing practices? In-memory Postgres mock for high-speed acceptance testing?
https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#passing-props-from-server-to-client-components-serialization
with nextjs you can’t do the same thing I did here (https://github.com/rphlmr/drizzle-on-indexeddb/blob/main/app/database/.client/db.ts)
importing a json like that is a Vite feature.
But since a JSON is serializable, you should be able to use what is described in the nextjs doc.
If I find some room in my schedule I could create a demo
20 replies
DTDrizzle Team
•Created by lolmaus (Andrey Mikhaylov) on 10/27/2023 in #help
Acceptance testing practices? In-memory Postgres mock for high-speed acceptance testing?
Should be fine in a client component (for the indexeddb part).
I guess you could have a server component that get the migration and forward it to the client component 👀
20 replies
DTDrizzle Team
•Created by lolmaus (Andrey Mikhaylov) on 10/27/2023 in #help
Acceptance testing practices? In-memory Postgres mock for high-speed acceptance testing?
I have a demo too https://github.com/rphlmr/drizzle-on-indexeddb
20 replies
DTDrizzle Team
•Created by ijohnston on 11/21/2024 in #help
Supabase [users.id]
what is
usersInAuth
? But do answer, yes you can re import again from /supabase
if it is authUsers. These imports are just here to be used as references in schema/relations5 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
For example, I’m referring to this: const db = await createDrizzleSupabaseClient(); const [user] = await db.rls((tx) => tx.select().from(profiles).where(eq(profiles.email, email)) );What happens here, based on the demo repo:
const db = await createDrizzleSupabaseClient();
We get back a db
object that is preset with our current user access_token. The token has been found in createDrizzleSupabaseClient
, using Supabase auth (it reads auth from the current HTTP request cookie).
this db
object contains 2 things: admin
and rls
.
admin
is a Drizzle client created with the default Supabase PG connection string (full-power user).
rls
is a Drizzle client we created with our low power PG user. This special client is a function: a drizzle transaction()
function.
Why? Because this is the only way to use RLS, the only way to set the user's request.jwt.claims
, isolated, per request.
This is what makes it possible to authenticate our SQL query.
Then, your RLS, on your postgres db will read this claims through auth.uid()
/ next_auth.uid()
(because these function read from the postgres query context config
and returns the value for the key request.jwt.claims
)42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
I also don’t fully understand how this data fetching, editing works with RLS.I would advise watching some Supabase videos about RLS and why you may need them. RLS is a collection of rules that define who can read and/or write/update/delete a particular row based on some criteria (auth state, user_id, etc)
42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
My problem begins with the fact that I can’t find where you export the db object, so I can’t reference it anywhere in my code. Why should I export it?If you have previously used Drizzle (with or without Supabase), it's just a drop-in replacement for the
db
object you export from (for example) database/db.ts
. It's a server side utils (it should not be used client side).
You export it because you need to set the current user's access token per request when the code is invoked. The RLS client makes isolated queries from other users because we use a Postgres transaction.42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
why exactly is it necessary to make the auth.js token compatible with Supabase?RLS relies on user auth (through an access token). By design, RLS works with Supabase Auth. I don't know Auth.js, but it seems to be an alternative to Supabase Auth. It provides a way to manage authentication by creating a schema+db (like Supabase) in your PostgreSQL database. Side note: We are not directly concerned, but, in order to be able to use Supabase SDK with an external auth system (like Authjs), you have to make Supabase aware of that (Supabase SDK is a web API that forwards your queries). This is why the doc speak about Supabase client etc. In our case, we don't really need all of this, we only need to pass a decoded access token to the PostgreSQL config (
request.jwt.claim.sub
). Then, you will be able to create policies using the helper next_auth.uid()
to check who is querying (e.g., https://supabase.com/docs/guides/database/postgres/row-level-security). Because you are not using Supabase Auth, in these examples, you would have to replace auth.uid()
with next_auth.uid()
.42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
Now you have to figure how you get your session from auth js here.
Maybe its
https://authjs.dev/getting-started/adapters/supabase#typescript
But I know nothing about auth.js, so I would not give wrong information.
42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
Of course, you could use
jsonwebtoken
to decode the token in jwt.ts
, but we really only need the access_token decoded (so it's on you to assert that it is a legitimate token. I guess Auth.js handles all of this)42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
Reading the linked documentation, everything can be identical to what is in the demo repo since Auth.js also relies on
request.jwt.claim.sub
for its postgres next_auth.uid()
function.
The only thing that differs is in my db.ts
42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
Can I assume that you know auth.js and have installed it as described in the documentation you linked?
42 replies