0
Run Arbitrary Query
One script reply has been approved by the moderators Verified
Created by adam186 385 days ago Viewed 5152 times
0
Submitted by adam186 Deno
Verified 385 days ago
1
import Surreal from "https://deno.land/x/surrealdb@v0.5.0/mod.ts";
2

3
/**
4
 * @param query The query string.
5
 * @param variables The variables used in the query.
6
 */
7
type Surrealdb = {
8
  url: string;
9
  token: string;
10
};
11
export async function main(
12
  auth: Surrealdb,
13
  namespace: string,
14
  database: string,
15
  query: string,
16
  variables?: Record<string, unknown>,
17
) {
18
  const client = new Surreal(auth.url, auth.token);
19
  await client.use(namespace, database);
20
  const result = await client.query(query, variables);
21
  client.close();
22
  return result;
23
}
24