drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[FEATURE]: Support react-native-quick-sqlite

Open peterlazar1993 opened this issue 1 year ago • 3 comments

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!

peterlazar1993 avatar Jun 04 '23 19:06 peterlazar1993

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 avatar Jun 05 '23 13:06 elevyg

@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.

peterlazar1993 avatar Jun 05 '23 13:06 peterlazar1993

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.

elevyg avatar Jun 06 '23 17:06 elevyg

This would be great 👍🏼

L-U-C-K-Y avatar Sep 30 '23 07:09 L-U-C-K-Y

this would be awesome! Would be nice if it supported expo sqlite as well.

RaghavBhat02 avatar Oct 04 '23 07:10 RaghavBhat02

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 });
        }
    }
});

Zoxive avatar Nov 17 '23 15:11 Zoxive

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.

https://github.com/OP-Engineering/op-sqlite

ospfranco avatar Nov 17 '23 15:11 ospfranco