@@ -45,124 +45,4 @@ export const db = wrapPowerSyncWithKysely<Database>(powerSyncDb)
4545
4646For more information on Kysely typing, see [ here] ( https://kysely.dev/docs/getting-started#types ) .
4747
48- Now you are able to use Kysely queries:
49-
50- ### Select
51-
52- - In Kysely
53-
54- ``` js
55- const result = await db .selectFrom (' users' ).selectAll ().execute ();
56-
57- // [{ id: '1', name: 'user1' }, { id: '2', name: 'user2' }]
58- ```
59-
60- - In PowerSync
61-
62- ``` js
63- const result = await powerSyncDb .getAll (' SELECT * from users' );
64-
65- // [{ id: '1', name: 'user1' }, { id: '2', name: 'user2' }]
66- ```
67-
68- ### Insert
69-
70- - In Kysely
71-
72- ``` js
73- await db .insertInto (' users' ).values ({ id: ' 1' , name: ' John' }).execute ();
74- const result = await db .selectFrom (' users' ).selectAll ().execute ();
75-
76- // [{ id: '1', name: 'John' }]
77- ```
78-
79- - In PowerSync
80-
81- ``` js
82- await powerSyncDb .execute (' INSERT INTO users (id, name) VALUES(1, ?)' , [' John' ]);
83- const result = await powerSyncDb .getAll (' SELECT * from users' );
84-
85- // [{ id: '1', name: 'John' }]
86- ```
87-
88- ### Delete
89-
90- - In Kysely
91-
92- ``` js
93- await db .insertInto (' users' ).values ({ id: ' 2' , name: ' Ben' }).execute ();
94- await db .deleteFrom (' users' ).where (' name' , ' =' , ' Ben' ).execute ();
95- const result = await db .selectFrom (' users' ).selectAll ().execute ();
96-
97- // []
98- ```
99-
100- - In PowerSync
101-
102- ``` js
103- await powerSyncDb .execute (' INSERT INTO users (id, name) VALUES(2, ?)' , [' Ben' ]);
104- await powerSyncDb .execute (` DELETE FROM users WHERE name = ?` , [' Ben' ]);
105- const result = await powerSyncDb .getAll (' SELECT * from users' );
106-
107- // []
108- ```
109-
110- ### Update
111-
112- - In Kysely
113-
114- ``` js
115- await db .insertInto (' users' ).values ({ id: ' 3' , name: ' Lucy' }).execute ();
116- await db .updateTable (' users' ).where (' name' , ' =' , ' Lucy' ).set (' name' , ' Lucy Smith' ).execute ();
117- const result = await db .selectFrom (' users' ).select (' name' ).executeTakeFirstOrThrow ();
118-
119- // 'Lucy Smith'
120- ```
121-
122- - In PowerSync
123-
124- ``` js
125- await powerSyncDb .execute (' INSERT INTO users (id, name) VALUES(3, ?)' , [' Lucy' ]);
126- await powerSyncDb .execute (' UPDATE users SET name = ? WHERE name = ?' , [' Lucy Smith' , ' Lucy' ]);
127- const result = await powerSyncDb .get (' SELECT name FROM users WHERE name = ?' , [' Lucy Smith' ])
128-
129- // 'Lucy Smith'
130- ```
131-
132- ### Transaction
133-
134- - In Kysely
135-
136- ``` js
137- await db .transaction ().execute (async (transaction ) => {
138- await transaction .insertInto (' users' ).values ({ id: ' 4' , name: ' James' }).execute ();
139- await transaction .updateTable (' users' ).where (' name' , ' =' , ' James' ).set (' name' , ' James Smith' ).execute ();
140- });
141- const result = await db .selectFrom (' users' ).select (' name' ).executeTakeFirstOrThrow ();
142-
143- // 'James Smith'
144- ```
145-
146- - In Kysely also using raw SQL
147-
148- ``` js
149- await db .transaction ().execute (async (transaction ) => {
150- await sql ` INSERT INTO users (id, name) VALUES (' 4' , ' James' );` .execute (transaction)
151- await transaction .updateTable (' users' ).where (' name' , ' =' , ' James' ).set (' name' , ' James Smith' ).execute ();
152- });
153- const result = await db .selectFrom (' users' ).select (' name' ).executeTakeFirstOrThrow ();
154-
155- // 'James Smith'
156- ```
157-
158- - In PowerSync
159-
160- ``` js
161- await powerSyncDb .writeTransaction ((transaction ) => {
162- await transaction .execute (' INSERT INTO users (id, name) VALUES(4, ?)' , [' James' ]);
163- await transaction .execute (" UPDATE users SET name = ? WHERE name = ?" , [' James Smith' , ' James' ]);
164- })
165- const result = await powerSyncDb .get (' SELECT name FROM users WHERE name = ?' , [' James Smith' ])
166-
167- // 'James Smith'
168- ```
48+ For more information on how to use Kysely queries in PowerSync, see [ here] ( https://docs.powersync.com/client-sdk-references/javascript-web/javascript-orm/kysely#usage-examples ) .
0 commit comments