-
-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support defining a db with jsonschema #445
Comments
Hi! Directly supporting JSONSchema could be technically feasible but with some limitations:
The most suitable solution is to create a library (plugin?) that translates JSONSchema in Orama, skipping untranslatable properties (or throw?). Anyway, this could be an amazing feature! WDYT @micheleriva? |
We just had a team discussion about this feature request and really liked it. Maybe we will be able to contribute. |
Based on @allevo 's feedback, I suggest something like this: import { create } from '@orama/orama'
import { schemaFromJson } from '@orama/jsonschema'
const movieDB = await create({
schema: schemaFromJson({
type: 'object',
properties: {
title: { type: 'string' },
director: { type: 'string' },
plot: { type: 'string' },
year: { type: 'number' },
isFavorite: { type: 'boolean' }
},
required: [ 'title', 'director', 'plot', 'year', 'isFavorite' ]
}),
}) An official plugin that exports a function that converts from a json schema to orama's schema format. |
This would pair nicely with typebox. |
Is your feature request related to a problem? Please describe.
JSON schema is a widely used and understood format for defining the shape of data structures. Existing applications already make use of it and have schemas written for entities. It would make adoption of orama search easier if a database could be created using a json schema rather than only the custom schema DDL that orama currently offers.
Describe the solution you'd like
Describe alternatives you've considered
Writing my own custom script to try and convert my existing json schemas into oramas schema format.
Additional context
JSON schema website: https://json-schema.org/
There is widely available tooling available for json schema, and generating json schema from almost any language.
Consider the case of a very complex ecommerce site with a Golang backend, all the entities are defined in Go structs and stored in Mongodb. They want frontend in-memory search. They would need to rewrite all their schemas in oramas format to make the fields searchable.
With my feature request, they could simply run their Go structs through a jsonschema generator such as https://github.com/invopop/jsonschema and then all fields are instantly searchable with no manual schema writing.
Additional benefit
Not the main feature request but a side benefit is that typescript types can be inferred from jsonschema, meaning the database could be automatically typed after being created with a jsonschema, so
insert
,update
andsearch
could all have the correct types without being specified by the user, since it gets inferred from the jsonschema.The text was updated successfully, but these errors were encountered: