-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple clone impl only on PGlite (#526)
* simple clone impl on PGlite --------- Co-authored-by: tudor <[email protected]>
- Loading branch information
1 parent
ea110d1
commit f94d591
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@electric-sql/pglite': patch | ||
--- | ||
|
||
added clone() method to pglite API. clones an instance such that it can be reused (for example running tests on existing data without readding all data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { describe, it, expect } from 'vitest' | ||
import { PGlite } from '../dist/index.js' | ||
|
||
describe('clone', () => { | ||
it('clone pglite instance', async () => { | ||
const pg1 = new PGlite() | ||
await pg1.exec(` | ||
CREATE TABLE IF NOT EXISTS test ( | ||
id SERIAL PRIMARY KEY, | ||
name TEXT | ||
); | ||
`) | ||
await pg1.exec("INSERT INTO test (name) VALUES ('test');") | ||
|
||
const pg2 = await pg1.clone() | ||
|
||
const ret1 = await pg1.query('SELECT * FROM test;') | ||
const ret2 = await pg2.query('SELECT * FROM test;') | ||
|
||
expect(ret1).toEqual(ret2) | ||
}) | ||
|
||
it('clone pglite instance - insert into pg2', async () => { | ||
const pg1 = new PGlite() | ||
await pg1.exec(` | ||
CREATE TABLE IF NOT EXISTS test ( | ||
id SERIAL PRIMARY KEY, | ||
name TEXT | ||
); | ||
`) | ||
await pg1.exec("INSERT INTO test (name) VALUES ('test');") | ||
|
||
const pg2 = await pg1.clone() | ||
await pg2.exec("INSERT INTO test (name) VALUES ('2-test');") | ||
|
||
const ret1 = await pg1.query('SELECT * FROM test;') | ||
const ret2 = await pg2.query('SELECT * FROM test;') | ||
|
||
expect(ret1.rows.length).toBe(1) | ||
expect(ret2.rows.length).toBe(2) | ||
}) | ||
}) |