Skip to content

Commit

Permalink
docs(providers): update surrealdb.mdx (#11905)
Browse files Browse the repository at this point in the history
* Update surrealdb.mdx

* fix: correct params to surrealDB adapter

* Update surrealdb.mdx

---------

Co-authored-by: Balázs Orbán <info@balazsorban.com>
  • Loading branch information
liamwh and balazsorban44 authored Sep 26, 2024
1 parent 532761a commit b86f7bb
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions docs/pages/getting-started/adapters/surrealdb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,34 @@ The SurrealDB adapter does not handle connections automatically, so you will hav
import { Surreal } from "surrealdb.js"

const connectionString = process.env.AUTH_SURREALDB_CONNECTION
const user = process.env.AUTH_SURREALDB_USERNAME
const pass = process.env.AUTH_SURREALDB_PASSWORD
const ns = process.env.AUTH_SURREALDB_NS
const db = process.env.AUTH_SURREALDB_DB
const username = process.env.AUTH_SURREALDB_USERNAME
const password = process.env.AUTH_SURREALDB_PASSWORD
const namespace = process.env.AUTH_SURREALDB_NAMESPACE
const database = process.env.AUTH_SURREALDB_DATABASE
if (!connectionString || !username || !password || !namespace || !database) {
throw new Error(
"SurrealDB connection string, username, password, namespace, and database are required"
)
}

const clientPromise = new Promise<Surreal>(async (resolve, reject) => {
const db = new Surreal()
try {
await db.connect(`${connectionString}/rpc`, {
ns,
db,
auth: { user, pass },
namespace,
database,
auth: {
username,
password,
},
})
resolve(db)
} catch (e) {
reject(e)
}
})

// Export a module-scoped MongoClient promise. By doing this in a
// Export a module-scoped Promise<Surreal>. By doing this in a
// separate module, the client can be shared across functions.
export default clientPromise
```
Expand All @@ -137,19 +145,27 @@ Useful in serverless environments like Vercel.
import { ExperimentalSurrealHTTP } from "surrealdb.js"

const connectionString = process.env.AUTH_SURREALDB_CONNECTION
const user = process.env.AUTH_SURREALDB_USERNAME
const pass = process.env.AUTH_SURREALDB_PASSWORD
const ns = process.env.AUTH_SURREALDB_NS
const db = process.env.AUTH_SURREALDB_DB
const username = process.env.AUTH_SURREALDB_USERNAME
const password = process.env.AUTH_SURREALDB_PASSWORD
const namespace = process.env.AUTH_SURREALDB_NAMESPACE
const database = process.env.AUTH_SURREALDB_DATABASE
if (!connectionString || !username || !password || !namespace || !database) {
throw new Error(
"SurrealDB connection string, username, password, namespace, and database are required"
)
}

const clientPromise = new Promise<ExperimentalSurrealHTTP<typeof fetch>>(
async (resolve, reject) => {
try {
const db = new ExperimentalSurrealHTTP(connectionString, {
fetch,
ns,
db,
auth: { user, pass },
namespace,
database,
auth: {
username,
password,
},
})
resolve(db)
} catch (e) {
Expand All @@ -158,7 +174,7 @@ const clientPromise = new Promise<ExperimentalSurrealHTTP<typeof fetch>>(
}
)

// Export a module-scoped MongoClient promise. By doing this in a
// Export a module-scoped Promise<Surreal>. By doing this in a
// separate module, the client can be shared across functions.
export default clientPromise
```

0 comments on commit b86f7bb

Please sign in to comment.