Open peterlazar1993 opened 1 year ago
I'd be amazing!. I'm trying to find a solution to easily sync server and an offline react native app. I've been trying using watermelondb and quick-sqlite to implement this feature but I'd be way more easy if I could use the same ORM both in the server and backend.
Currently I'm using Prisma in the backend but it seems they are not interested on supporting React Native.
@elevyg If you need proper sync, you might be better off using https://rxdb.info/ or https://github.com/craftzdog/pouchdb-react-native
But I think both would require your backend be based on couchdb.
PouchDb looks like is not having support anymore and RxDb despite being open source has a premium package that I don't like.
I think there is space for something more similar to watermelon db but written in a more declarative way.
This would be great 👍🏼
this would be awesome! Would be nice if it supported expo sqlite as well.
this would be awesome! Would be nice if it supported expo sqlite as well.
You can use the sqlite-proxy pretty easily.
Heres a quick and dirty example:
import { drizzle } from "drizzle-orm/sqlite-proxy";
import * as SQLite from 'expo-sqlite';
import * as schema from "./schema";
export const expoSql = SQLite.openDatabase('mydb.db');
export const db = drizzle(async (sql, params, method) => {
try {
const results = await expoSql.execAsync([{ sql, args: params }], false);
const rows = (results[0] as SQLite.ResultSet).rows;
if (method === 'get') {
if (rows.length === 0) return { rows: null as any };
// The typescript apis wants an array, but it seems more likely that get methods want a single item
return { rows: rows[0] as any };
}
return { rows: rows };
} catch (e) {
error('Error in db.ts:', e);
return { rows: [] };
}
}, {
schema: schema,
logger: {
logQuery: function (query: string, params: unknown[]): void {
console.log('[DRIZZLE] Query', { query, params });
}
}
});
I created a new package, based on quick-sqlite. It's muc faster and I also implemented the update_hook, which I guess is needed by drizzle.
Describe want to want
React Native has a really good SQLite library https://github.com/margelo/react-native-quick-sqlite authored by @ospfranco and now maintained by @margelo.
TypeORM supports RN but this is currently broken, it would be awesome if drizzle had an adapter for quick-sqlite!