powersync-ja / powersync-js

SDK that enables local-first and real-time reactive apps with embedded SQLite for JavaScript clients, including React Native and Web
https://www.powersync.com
Apache License 2.0
253 stars 13 forks source link

Improve JS docs with one example with Kysely syntax #275

Open guillempuche opened 3 weeks ago

guillempuche commented 3 weeks ago

https://docs.powersync.com/client-sdk-references/js-web#using-powersync-crud-functions

Apart from showing SQL syntax, show Kysely syntax, e.g.useQuery(kysely.selectFrom...)

benitav commented 3 weeks ago

That's a good suggestion, thanks! We can add the Kysely equivalent to the examples.

guillempuche commented 3 weeks ago

How would you transform this

https://github.com/guillempuche/localfirst_react_server/blob/d383ab33a01ffff866d5324dada0e6678c3bc0c6/apps/web/src/pages/page_home.effect.tsx#L9 to dbEffect.selectFrom...,

imatge

Right now, I use dbEffect for updating https://github.com/guillempuche/localfirst_react_server/blob/d383ab33a01ffff866d5324dada0e6678c3bc0c6/apps/web/src/components/editor.effect.tsx#L43


Discord thread https://discord.com/channels/1138230179878154300/1266491006593798165/1276214618217386035

guillempuche commented 3 weeks ago

I haven't run it, but it compiles: https://github.com/guillempuche/localfirst_react_server/blob/a1295f7e773cdc99c091881292c67fa7980d15a3/apps/web/src/pages/page_home.tsx#L8-L12

benitav commented 2 weeks ago

Just to close the loop here: Looks like you got this to work, if I follow the Discord thread?

const watchQuotes = useQuery<QuoteQuery>(
        'SELECT * FROM quotes ORDER BY id DESC',
    )
    const watchQuotesEffect = useQuery(
        dbEffect.selectFrom('quotes').orderBy('id', 'desc').selectAll(),
    )
guillempuche commented 2 weeks ago

Yes, i did