@@ -105,26 +105,34 @@ The SurrealDB adapter does not handle connections automatically, so you will hav
105
105
import { Surreal } from " surrealdb.js"
106
106
107
107
const connectionString = process .env .AUTH_SURREALDB_CONNECTION
108
- const user = process .env .AUTH_SURREALDB_USERNAME
109
- const pass = process .env .AUTH_SURREALDB_PASSWORD
110
- const ns = process .env .AUTH_SURREALDB_NS
111
- const db = process .env .AUTH_SURREALDB_DB
108
+ const username = process .env .AUTH_SURREALDB_USERNAME
109
+ const password = process .env .AUTH_SURREALDB_PASSWORD
110
+ const namespace = process .env .AUTH_SURREALDB_NAMESPACE
111
+ const database = process .env .AUTH_SURREALDB_DATABASE
112
+ if (! connectionString || ! username || ! password || ! namespace || ! database ) {
113
+ throw new Error (
114
+ " SurrealDB connection string, username, password, namespace, and database are required"
115
+ )
116
+ }
112
117
113
118
const clientPromise = new Promise <Surreal >(async (resolve , reject ) => {
114
119
const db = new Surreal ()
115
120
try {
116
121
await db .connect (` ${connectionString }/rpc ` , {
117
- ns ,
118
- db ,
119
- auth: { user , pass },
122
+ namespace ,
123
+ database ,
124
+ auth: {
125
+ username ,
126
+ password ,
127
+ },
120
128
})
121
129
resolve (db )
122
130
} catch (e ) {
123
131
reject (e )
124
132
}
125
133
})
126
134
127
- // Export a module-scoped MongoClient promise . By doing this in a
135
+ // Export a module-scoped Promise<Surreal> . By doing this in a
128
136
// separate module, the client can be shared across functions.
129
137
export default clientPromise
130
138
```
@@ -137,19 +145,27 @@ Useful in serverless environments like Vercel.
137
145
import { ExperimentalSurrealHTTP } from " surrealdb.js"
138
146
139
147
const connectionString = process .env .AUTH_SURREALDB_CONNECTION
140
- const user = process .env .AUTH_SURREALDB_USERNAME
141
- const pass = process .env .AUTH_SURREALDB_PASSWORD
142
- const ns = process .env .AUTH_SURREALDB_NS
143
- const db = process .env .AUTH_SURREALDB_DB
148
+ const username = process .env .AUTH_SURREALDB_USERNAME
149
+ const password = process .env .AUTH_SURREALDB_PASSWORD
150
+ const namespace = process .env .AUTH_SURREALDB_NAMESPACE
151
+ const database = process .env .AUTH_SURREALDB_DATABASE
152
+ if (! connectionString || ! username || ! password || ! namespace || ! database ) {
153
+ throw new Error (
154
+ " SurrealDB connection string, username, password, namespace, and database are required"
155
+ )
156
+ }
144
157
145
158
const clientPromise = new Promise <ExperimentalSurrealHTTP <typeof fetch >>(
146
159
async (resolve , reject ) => {
147
160
try {
148
161
const db = new ExperimentalSurrealHTTP (connectionString , {
149
162
fetch ,
150
- ns ,
151
- db ,
152
- auth: { user , pass },
163
+ namespace ,
164
+ database ,
165
+ auth: {
166
+ username ,
167
+ password ,
168
+ },
153
169
})
154
170
resolve (db )
155
171
} catch (e ) {
@@ -158,7 +174,7 @@ const clientPromise = new Promise<ExperimentalSurrealHTTP<typeof fetch>>(
158
174
}
159
175
)
160
176
161
- // Export a module-scoped MongoClient promise . By doing this in a
177
+ // Export a module-scoped Promise<Surreal> . By doing this in a
162
178
// separate module, the client can be shared across functions.
163
179
export default clientPromise
164
180
```
0 commit comments