Load a previously saved database state into an Orama instance
Restores a database instance from raw serialized data. This function loads the internal state of an Orama database, including the index, documents, sorting data, and pinning rules.
import { create, insert, save, load } from '@orama/orama'// Create and populate a databaseconst originalDB = await create({ schema: { title: 'string', description: 'string', price: 'number' }})await insert(originalDB, { title: 'Wireless Headphones', description: 'High-quality wireless headphones', price: 99.99})// Save the database stateconst rawData = await save(originalDB)// Create a new database instance with the same schemaconst newDB = await create({ schema: { title: 'string', description: 'string', price: 'number' }})// Load the saved state into the new instanceload(newDB, rawData)// The new database now has the same state as the originalconst results = await search(newDB, { term: 'wireless'})
import { create, load, save } from '@orama/orama'// Original database in Spanishconst spanishDB = await create({ schema: { titulo: 'string', contenido: 'string' }, language: 'spanish'})await insert(spanishDB, { titulo: 'Hola mundo', contenido: 'Este es un documento en español'})const savedData = await save(spanishDB)// Load into a new instance - language will be restored from saved dataconst restoredDB = await create({ schema: { titulo: 'string', contenido: 'string' }, language: 'english' // This will be overwritten by saved data})load(restoredDB, savedData)// The tokenizer language is now 'spanish' from the loaded dataconsole.log(restoredDB.tokenizer.language) // 'spanish'