next-url-shortener/src/components/db-utils.tsx
2024-02-15 15:11:46 -08:00

23 lines
414 B
TypeScript

import { Surreal } from 'surrealdb.js';
require('dotenv');
const db = new Surreal();
export async function initConnection(): Promise<Surreal> {
try {
db.connect(process.env.DB_PORT + '/rpc', {
namespace: 'url',
database: 'url',
auth: {
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
scope: '',
},
});
} catch (e) {
console.error('ERROR', e);
}
return db;
}