import { create, AnySchema, Schema } from '@orama/orama';
// Define schema
const productSchema = {
id: 'string',
title: 'string',
description: 'string',
price: 'number',
inStock: 'boolean',
tags: 'string[]',
ratings: 'number[]',
category: 'enum',
location: 'geopoint',
embedding: 'vector[384]',
metadata: {
brand: 'string',
sku: 'string',
weight: 'number'
}
} satisfies AnySchema;
// Create database with typed schema
const db = await create({
schema: productSchema
});
// TypeScript infers document type
type Product = Schema<typeof productSchema>;
// Insert with full type safety
await db.insert({
id: '1',
title: 'Laptop',
description: 'High-performance laptop',
price: 999.99,
inStock: true,
tags: ['electronics', 'computers'],
ratings: [4.5, 4.8, 5.0],
category: 'electronics',
location: { lat: 40.7128, lon: -74.0060 },
embedding: new Array(384).fill(0),
metadata: {
brand: 'TechCorp',
sku: 'LAP-001',
weight: 2.5
}
});