-
Notifications
You must be signed in to change notification settings - Fork 49
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
12 changed files
with
236 additions
and
60 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type Surreal from "../../src"; | ||
|
||
export async function fetchVersion(surreal: Surreal): Promise<string> { | ||
return (await surreal.version()).replace(/^surrealdb-/, ""); | ||
} |
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,94 @@ | ||
// Bun Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`export basic 1`] = ` | ||
"-- ------------------------------ | ||
-- OPTION | ||
-- ------------------------------ | ||
OPTION IMPORT; | ||
-- ------------------------------ | ||
-- FUNCTIONS | ||
-- ------------------------------ | ||
DEFINE FUNCTION fn::foo() { RETURN 'bar'; } PERMISSIONS FULL; | ||
-- ------------------------------ | ||
-- TABLE: bar | ||
-- ------------------------------ | ||
DEFINE TABLE bar TYPE ANY SCHEMALESS PERMISSIONS NONE; | ||
-- ------------------------------ | ||
-- TABLE DATA: bar | ||
-- ------------------------------ | ||
INSERT [ { hello: 'world', id: bar:1 } ]; | ||
-- ------------------------------ | ||
-- TABLE: foo | ||
-- ------------------------------ | ||
DEFINE TABLE foo TYPE ANY SCHEMALESS PERMISSIONS NONE; | ||
-- ------------------------------ | ||
-- TABLE DATA: foo | ||
-- ------------------------------ | ||
INSERT [ { hello: 'world', id: foo:1 } ]; | ||
" | ||
`; | ||
|
||
exports[`export filter tables 1`] = ` | ||
"-- ------------------------------ | ||
-- OPTION | ||
-- ------------------------------ | ||
OPTION IMPORT; | ||
-- ------------------------------ | ||
-- FUNCTIONS | ||
-- ------------------------------ | ||
DEFINE FUNCTION fn::foo() { RETURN 'bar'; } PERMISSIONS FULL; | ||
-- ------------------------------ | ||
-- TABLE: foo | ||
-- ------------------------------ | ||
DEFINE TABLE foo TYPE ANY SCHEMALESS PERMISSIONS NONE; | ||
-- ------------------------------ | ||
-- TABLE DATA: foo | ||
-- ------------------------------ | ||
INSERT [ { hello: 'world', id: foo:1 } ]; | ||
" | ||
`; | ||
|
||
exports[`export filter functions 1`] = ` | ||
"-- ------------------------------ | ||
-- OPTION | ||
-- ------------------------------ | ||
OPTION IMPORT; | ||
-- ------------------------------ | ||
-- FUNCTIONS | ||
-- ------------------------------ | ||
DEFINE FUNCTION fn::foo() { RETURN 'bar'; } PERMISSIONS FULL; | ||
" | ||
`; |
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,46 @@ | ||
import { beforeAll, describe, expect, test } from "bun:test"; | ||
import { compareVersions } from "compare-versions"; | ||
import { surql } from "../../../src"; | ||
import { fetchVersion } from "../helpers.ts"; | ||
import { setupServer } from "../surreal.ts"; | ||
|
||
const { createSurreal } = await setupServer(); | ||
|
||
beforeAll(async () => { | ||
const surreal = await createSurreal(); | ||
|
||
await surreal.query(surql` | ||
CREATE foo:1 CONTENT { hello: "world" }; | ||
CREATE bar:1 CONTENT { hello: "world" }; | ||
DEFINE FUNCTION fn::foo() { RETURN "bar"; }; | ||
`); | ||
}); | ||
|
||
describe("export", async () => { | ||
const surreal = await createSurreal(); | ||
const version = await fetchVersion(surreal); | ||
const hasPostExport = compareVersions(version, "2.1.0") >= 0; | ||
|
||
test.if(hasPostExport)("basic", async () => { | ||
const res = await surreal.export(); | ||
|
||
expect(res).toMatchSnapshot(); | ||
}); | ||
|
||
test.if(hasPostExport)("filter tables", async () => { | ||
const res = await surreal.export({ | ||
tables: ["foo"], | ||
}); | ||
|
||
expect(res).toMatchSnapshot(); | ||
}); | ||
|
||
test.if(hasPostExport)("filter functions", async () => { | ||
const res = await surreal.export({ | ||
functions: true, | ||
tables: false, | ||
}); | ||
|
||
expect(res).toMatchSnapshot(); | ||
}); | ||
}); |
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.