-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate_chunks.js
More file actions
41 lines (36 loc) · 1.07 KB
/
populate_chunks.js
File metadata and controls
41 lines (36 loc) · 1.07 KB
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
require('dotenv').config();
const fs = require('fs');
const { createClient } = require('@supabase/supabase-js');
// Read the JSON file
const jsonData = fs.readFileSync('express_entry_data.json', 'utf-8');
const data = JSON.parse(jsonData);
const chunks = data.chunks;
// Connect to your Supabase database
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
const supabaseKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);
// Insert the chunks into the database
const insertChunks = async () => {
for (const chunk of chunks) {
const { data, error } = await supabase
.from('chunks')
.insert([
{
url: chunk.url,
title: chunk.title,
content: chunk.content,
length: chunk.length,
tokens: chunk.tokens,
},
]);
if (error) {
console.error('Error inserting chunk:', error);
} else {
console.log('Chunk inserted successfully:', data);
}
}
};
// Wrap the call to insertChunks in an IIFE
(async () => {
await insertChunks();
})();