Drizzle for Expo SQLite #2447
Replies: 7 comments 9 replies
-
Hey @AlexBlokh , really awesome feature! Just one callout for documentation when ya'll get a moment, but I found that so change... const expo = openDatabaseSync('db.db'); to const expo = openDatabaseSync("db.db", { enableChangeListener: true }) And it works like a dream. Thanks again for this stellar feature; excited to put it to use! 🚀 |
Beta Was this translation helpful? Give feedback.
-
Thanks! it works great. I don't know if this just happened to me but, I had a table with a underscore "expo": "^51.0.18", Test environment: |
Beta Was this translation helpful? Give feedback.
-
Hey guys, very nice update, thanks for that! I have one question thought, what if I want to subscribe to a query with dynamic where parameters? const todos = useLiveQuery(
db.query.todos.findMany({
where: between(schema.todos.created_at, from, to),
})
) The To be clear I've tried it and it didn't work 🥲 |
Beta Was this translation helpful? Give feedback.
-
I have also one question, I am not sure, if I understand this correctly. This type of live query is not refreshing when I add new collection item:
with this schema:
|
Beta Was this translation helpful? Give feedback.
-
Hey - Thanks for the great implementation, it's been really fun working with Drizzle in Expo/React Native. I am using Some Pseudo Code # userId coming from route or props
const { data } = useLiveQuery(
db
.select()
.from(lotsTable)
.where(
eq(userId, userId),
),
[userId],
); This work as expected, if Im working on optimising for slower devices and this is a big one if implemented in a provider/context I did some poking around and here it seems like My expectations is: if the data my query is selecting is changing ,re-render, not re-render on any changes in the table, but that might be wrong? Seems like it could be a simple fix, but I could be missing something bigger, happy to submit a PR if you think this is the correct direction. const handleData = (data: any) => {
// if data is empty or undefined exit early
if (!data || data.length === 0) {
return;
}
setData(data);
setUpdatedAt(new Date());
};
|
Beta Was this translation helpful? Give feedback.
-
Hello, I'm running into what I think are related issues to what @ahwelgemoed posted about. It seems like the dep array isn't doing anything. I have this test function that anytime I update the "users" table, it causes the "groups" query to re-render if they are in the same component. If I remove the users query from the component and update that table, it does not cause the groups query to re-render.
|
Beta Was this translation helpful? Give feedback.
-
how to integrate drizzle orm using the |
Beta Was this translation helpful? Give feedback.
-
With Drizzle we want to deliver the best DX for native mobile development of local first applications
Based on our practical experience of mobile development - we narrowed down on 4 parts of the puzzle:
Drizzle ORM and migrations
As of
v0.29.2
- Drizzle ORM natively supports Expo SQLitewe've implemented Expo SQLite support for Drizzle Kit to conveniently generate SQL migrations. Unfortunately there's no way to run generate migrations from the CLI(like on the backend), since there's an isolated local database on each phone your applications are installed and you have to bundle migrations into application and run them on the device. We made sure it's as simple as possible - see docs
now you can generate migrations with
drizzle-kit generate
and import them to your appDrizzle Studio
For Drizzle Studio to work with Expo SQLite the only way is to have a dev tool plugin, so we build one - see here
That's it, you can now run Expo App on the simulator or physical device with
npx expo start
then pressshift + m
and choozeexpo-drizzle-studio-plugin
from the list!Live Queries 🎉
As of
v0.31.1
Drizzle ORM now has native support for Expo SQLite Live Queries!We've implemented a native
useLiveQuery
React Hook which observes necessary database changes and automatically re-runs database queries. It works with both SQL-like and Drizzle Queries:We've intentionally not changed the API of ORM itself to stay with conventional React Hook API, so we have
useLiveQuery(databaseQuery)
as opposed todb.select().from(users).useLive()
ordb.query.users.useFindMany()
We've also decided to provide
data
,error
andupdatedAt
fields as a result of hook for concise explicit error handling following practices ofReact Query
andElectric SQL
Beta Was this translation helpful? Give feedback.
All reactions