-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample-type-select.ts
42 lines (36 loc) · 1.03 KB
/
sample-type-select.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
import { Surreal } from 'surrealdb';
export class RagEmbeddingCollection {
title: string;
file: string;
path: string;
filePath: string;
sha256: string | unknown;
chunks: number;
creator: string;
processing?: boolean;
}
// Initialize the SurrealDB client
const db = new Surreal('http://localhost:8888');
// Function to fetch data
async function fetchRagEmbeddingCollections(): Promise<RagEmbeddingCollection[]> {
try {
// Connect to the database
await db.connect('root', 'root');
// Perform the SELECT query and type the result
const result = await db.select<RagEmbeddingCollection>('RagEmbeddingCollection');
// Return the typed result
return result;
} catch (error) {
console.error('Failed to fetch data:', error);
return [];
} finally {
// Close the database connection
await db.close();
}
}
// Usage
fetchRagEmbeddingCollections().then((collections) => {
collections.forEach((collection) => {
console.log(collection.title); // Access properties with type safety
});
});