Initial commit
This commit is contained in:
28
scripts/import_categories.js
Normal file
28
scripts/import_categories.js
Normal file
@ -0,0 +1,28 @@
|
||||
const PocketBase = require('pocketbase').default
|
||||
|
||||
// Initialize the PocketBase client
|
||||
const pb = new PocketBase('http://127.0.0.1:8090')
|
||||
|
||||
async function main () {
|
||||
try {
|
||||
// Authenticate as an admin
|
||||
await pb.admins.authWithPassword('karkinge@gmail.com', 'PBk4rk1ng3*') // Replace with your admin credentials
|
||||
|
||||
// Parse JSON file with categories
|
||||
const data = require('../../gyoza/database_backups/20250320.json')
|
||||
console.log(data.categories)
|
||||
|
||||
// Perform some operations, e.g., create a new record in the 'categories' collection
|
||||
for (let category of data.categories) {
|
||||
const newCategory = await pb.collection('categories').create({
|
||||
code: category.code,
|
||||
name: category.name
|
||||
})
|
||||
console.log('New category created:', newCategory)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
Reference in New Issue
Block a user