@@ -153,6 +153,54 @@ added: v22.5.0
153153Compiles a SQL statement into a [ prepared statement] [ ] . This method is a wrapper
154154around [ ` sqlite3_prepare_v2() ` ] [ ] .
155155
156+ ### ` database.createSession([options]) `
157+
158+ * ` options ` {Object} An optional object used to configure the session.
159+ * ` table ` {string} When provided, only changes to this table are tracked by the created session.
160+ By default, changes to all tables are tracked.
161+ * Returns: {Session} A session handle.
162+
163+ Creates and attackes a session to the database. This method is a wrapper around [ ` sqlite3session_create() ` ] [ ] and [ ` sqlite3session_attach() ` ] [ ] .
164+
165+ ### ` database.applyChangeset(changeset[, options]) `
166+
167+ * ` changeset ` {Uint8Array} A binary changeset.
168+ * ` options ` {Object} An optional object.
169+ * ` filter ` {Function} Optional function that takes the name of a table as the first argument.
170+ When ` true ` is returned, includes the change, otherwise, it is discarded. When not provided
171+ no changes are filtered, and all are changes are attempted.
172+
173+ An exception is thrown if the database is not
174+ open. This method is a wrapper around [ ` sqlite3changeset_apply() ` ] [ ] .
175+
176+ Example usage is demonstrated below.
177+
178+ ``` js
179+ const database1 = new DatabaseSync (' :memory:' );
180+ const database2 = new DatabaseSync (' :memory:' );
181+
182+ database1 .exec (' CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)' );
183+ database2 .exec (' CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)' );
184+
185+ const session = database1 .createSession ();
186+
187+ const insert = database1 .prepare (' INSERT INTO data (key, value) VALUES (?, ?)' );
188+ insert .run (1 , ' hello' );
189+ insert .run (2 , ' world' );
190+
191+ const changeset = session .changeset ();
192+ database2 .applyChangeset (changeset); // Will now contain the same data as database1
193+ ```
194+
195+ ## Class: ` Session `
196+
197+ ### ` session.changeset() `
198+
199+ * Returns: {Uint8Array} Binary changeset that can be applied to other databases.
200+
201+ Retrieves a changeset containing all changes since the changeset was created. Can be called multiple times.
202+ An exception is thrown if the database is not open. This method is a wrapper around [ ` sqlite3session_changeset() ` ] [ ] .
203+
156204## Class: ` StatementSync `
157205
158206<!-- YAML
@@ -323,6 +371,10 @@ exception.
323371[ `sqlite3_last_insert_rowid()` ] : https://www.sqlite.org/c3ref/last_insert_rowid.html
324372[ `sqlite3_prepare_v2()` ] : https://www.sqlite.org/c3ref/prepare.html
325373[ `sqlite3_sql()` ] : https://www.sqlite.org/c3ref/expanded_sql.html
374+ [ `sqlite3session_attach()` ] : https://www.sqlite.org/session/sqlite3session_attach.html
375+ [ `sqlite3session_create()` ] : https://www.sqlite.org/session/sqlite3session_create.html
376+ [ `sqlite3session_changeset()` ] : https://www.sqlite.org/session/sqlite3session_changeset.html
377+ [ `sqlite3changeset_apply()` ] : https://www.sqlite.org/session/sqlite3changeset_apply.html
326378[ connection ] : https://www.sqlite.org/c3ref/sqlite3.html
327379[ data types ] : https://www.sqlite.org/datatype3.html
328380[ in memory ] : https://www.sqlite.org/inmemorydb.html
0 commit comments