Create a new Orama instance
Create
We can create
a new instance (from now on database) with an indexing schema
.
The schema represents the structure of the document to be inserted.
A database can be as simple as:
import { create } from '@orama/orama'
const db = await create({
schema: {
word: 'string',
},
})
or more variegated:
import { create } from '@orama/orama'
const movieDB = await create({
schema: {
title: 'string',
director: 'string',
plot: 'string',
year: 'number',
isFavorite: 'boolean',
},
})
Nested properties
Orama supports nested properties natively. Just add them as you would typically do in any JavaScript object:
const movieDB = await create({
schema: {
title: 'string',
plot: 'string',
cast: {
director: 'string',
leading: 'string',
},
year: 'number',
isFavorite: 'boolean',
},
})
Multivalue fields
Orama also supports arrays as fields as well.
const db = await create({
schema: {
name: 'string[]',
numbers: 'number[]',
booleans: 'boolean[]',
},
})
Instance ID
Every Orama instance has a unique id
property, which can be used to identify a given instance when working with multiple databases.
You can customize it by passing an id
property during the creation of the instance:
import { create } from '@orama/orama'
const db = await create({
schema: {
word: 'string',
},
id: 'my-orama-instance'
})