-
Notifications
You must be signed in to change notification settings - Fork 0
/
edgedb.ts
85 lines (65 loc) · 2.09 KB
/
edgedb.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { Hono } from "hono";
import * as edgedb from "edgedb";
import e from "../dbschema/edgeql-js";
const route = new Hono();
route.get("/", async (c) =>
{
// using cloud EdgeDB instance
const client = edgedb.createHttpClient({
instanceName: (c.env as any).EDGEDB_INSTANCE,
secretKey: (c.env as any).EDGEDB_SECRET_KEY,
});
const query = "SELECT 1 + 1";
return c.text(`${query} = ${await client.query(query)}`);
});
route.get("/add-person", async (c) =>
{
const client = edgedb.createHttpClient({
instanceName: (c.env as any).EDGEDB_INSTANCE,
secretKey: (c.env as any).EDGEDB_SECRET_KEY,
});
const query = e.insert(e.Person, {
name: `Person #${Date.now()}`,
});
return c.json(await query.run(client));
});
route.get("/persons", async (c) =>
{
const client = edgedb.createHttpClient({
instanceName: (c.env as any).EDGEDB_INSTANCE,
secretKey: (c.env as any).EDGEDB_SECRET_KEY,
});
const query = e.select(e.Person, () => ({
...e.Person["*"]
}));
return c.json(await query.run(client));
});
// #region Failed Attempts
// createClient
route.get("/1", async (c) =>
{
// STATUS: Failed
// EdgeDBError: 'createClient()' cannot be used in browser(or edge runtime) environment, use 'createHttpClient()' API instead
const client = edgedb.createClient();
return c.json(await client.query("SELECT 1 + 1"));
});
// createHttpClient
route.get("/2", async (c) =>
{
// STATUS: Failed
// Client Connection Error: no connection options specified either by arguments to `createClient` API or environment variables; also cannot resolve from edgedb.toml in browser (or edge runtime) environment
const client = edgedb.createHttpClient();
return c.json(await client.query("SELECT 1 + 1"));
});
// using local EdgeDB instance
route.get("/3", async (c) =>
{
// STATUS: Failed
// WARNING: known issue with `fetch()` requests to custom HTTPS ports in published Workers
const client = edgedb.createHttpClient({
dsn: "edgedb://edgedb@localhost:10710/edgedb"
});
return c.json(await client.query("SELECT 1 + 1"));
});
// #endregion
export default route;