64 lines
1.3 KiB
TypeScript
64 lines
1.3 KiB
TypeScript
// point of sales core
|
|
|
|
interface Item {
|
|
id: string
|
|
name: string
|
|
price: number
|
|
// other properties...
|
|
}
|
|
|
|
interface Sale {
|
|
id: string
|
|
itemId: string
|
|
quantity: number
|
|
timestamp: Date
|
|
// other properties...
|
|
}
|
|
|
|
interface Inventory {
|
|
itemId: string
|
|
quantity: number
|
|
}
|
|
|
|
// import * as rocksdb from 'rocksdb'
|
|
|
|
// // Open a RocksDB database
|
|
// const db = open({ create_if_missing: true }, './mydb')
|
|
|
|
// // Put a key-value pair
|
|
// db.put('key', 'value', (err) => {
|
|
// if (err) throw err
|
|
// console.log('Key-value pair stored successfully')
|
|
// })
|
|
|
|
// // Get a value by key
|
|
// db.get('key', (err, value) => {
|
|
// if (err) throw err
|
|
// console.log('Retrieved value:', value)
|
|
// })
|
|
|
|
// // Close the database
|
|
// db.close((err) => {
|
|
// if (err) throw err
|
|
// console.log('Database closed')
|
|
// })
|
|
|
|
const level = require('level-rocksdb')
|
|
|
|
// 1) Create our database, supply location and options.
|
|
// This will create or open the underlying RocksDB store.
|
|
const db = level('./mydb')
|
|
|
|
// 2) Put a key & value
|
|
db.put('name', 'Level', function (err: any) {
|
|
if (err) return console.log('Ooops!', err) // some kind of I/O error
|
|
|
|
// 3) Fetch by key
|
|
db.get('name', function (err: any, value: any) {
|
|
if (err) return console.log('Ooops!', err) // likely the key was not found
|
|
|
|
// Ta da!
|
|
console.log('name=' + value)
|
|
})
|
|
})
|