-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,504 additions
and
494 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"pnpm":{"patchedDependencies":{"[email protected].0":"patches/[email protected].0.patch"}}} | ||
{"pnpm":{"patchedDependencies":{"[email protected].1":"patches/[email protected].1.patch"}}} |
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
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
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
3 changes: 2 additions & 1 deletion
3
packages/pglite/src/postgres.ts → packages/pglite/src/postgresMod.ts
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,44 @@ | ||
import test from "ava"; | ||
import { PGlite } from "../dist/index.js"; | ||
|
||
test("can create and call function", async (t) => { | ||
const db = new PGlite(); | ||
await db.exec(` | ||
CREATE EXTENSION IF NOT EXISTS plpgsql; | ||
CREATE OR REPLACE FUNCTION test_func() | ||
RETURNS TEXT AS $$ | ||
BEGIN | ||
RETURN 'test'; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
`); | ||
|
||
const res = await db.query("SELECT test_func();"); | ||
t.is(res.rows[0].test_func, "test"); | ||
}); | ||
|
||
test("can create and call complex function", async (t) => { | ||
const db = new PGlite(); | ||
await db.exec(` | ||
CREATE EXTENSION IF NOT EXISTS plpgsql; | ||
CREATE OR REPLACE FUNCTION calculate_factorial(n INT) RETURNS INT AS $$ | ||
DECLARE | ||
result INT := 1; | ||
BEGIN | ||
IF n < 0 THEN | ||
RAISE EXCEPTION 'The input cannot be negative.'; | ||
ELSIF n = 0 OR n = 1 THEN | ||
RETURN result; | ||
ELSE | ||
FOR i IN 2..n LOOP | ||
result := result * i; | ||
END LOOP; | ||
RETURN result; | ||
END IF; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
`); | ||
|
||
const res = await db.query("SELECT calculate_factorial(5) AS result;"); | ||
t.is(res.rows[0].result, 120); | ||
}); |
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
Oops, something went wrong.