Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use it with op-sqlite? #3

Open
MJRT opened this issue Aug 16, 2024 · 3 comments · May be fixed by #6
Open

How can I use it with op-sqlite? #3

MJRT opened this issue Aug 16, 2024 · 3 comments · May be fixed by #6

Comments

@MJRT
Copy link

MJRT commented Aug 16, 2024

It's seem only used for expo-sqlite

@MJRT
Copy link
Author

MJRT commented Aug 16, 2024

I try to use these code as poly fill, but get a vague errors, anyone know it?

import type { DB } from "@op-engineering/op-sqlite";
import { useDevToolsPluginClient } from "expo/devtools";
import { useEffect } from "react";

export default function useDrizzleStudio(db: DB | null) {
    const client = useDevToolsPluginClient("expo-drizzle-studio-plugin");

    const transferData = (e: {
        sql: string;
        params: (string | number)[];
        arrayMode: boolean;
        id: string;
    }) => {
        if (!db) return;
        try {
            const statement = db.prepareStatement(e.sql);
            statement.bind(e.params);
            const data = statement.execute();

            client?.sendMessage(`transferData-${e.id}`, { from: "app", data });
        } catch (error) {
            console.error('transfer Data error, event:', e);
            console.error(error);
    
    }
    };

    useEffect(() => {
        const subscriptions: any[] = [];

        subscriptions.push(client?.addMessageListener("getData", transferData));

        return () => {
            for (const subscription of subscriptions) {
                subscription?.remove();
            }
        };
    }, [client]);
}

PixPin_2024-08-17_01-35-59

@slvssb
Copy link

slvssb commented Nov 27, 2024

Hope this helps!
https://github.com/slvssb/drizzle-studio-expo/blob/slvssb/op-sqlite-support/src/useDrizzleStudio.tsx

@MJRT
Copy link
Author

MJRT commented Nov 27, 2024

@slvssb slvssb linked a pull request Nov 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants