@travetto/model-sqlite
v5.0.17
Published
SQLite backing for the travetto model module, with real-time modeling support for SQL schemas.
Downloads
710
Maintainers
Readme
SQLite Model Service
SQLite backing for the travetto model module, with real-time modeling support for SQL schemas.
Install: @travetto/model-sqlite
npm install @travetto/model-sqlite
# or
yarn add @travetto/model-sqlite
This module provides a SQLite-based implementation for the Data Modeling Support module. This source allows the Data Modeling Support module to read, write and query against SQL databases. In development mode, the SQLModelService will also modify the database schema in real time to minimize impact to development.
The schema generated will not generally map to existing tables as it is attempting to produce a document store like experience on top of a SQL database. Every table generated will have a path_id
which determines it's location in the document hierarchy as well as sub tables will have a parent_path_id
to associate records with the parent values.
Supported features:
- CRUD
- Bulk
- Query Crud
- Facet
- Query
- Suggest Out of the box, by installing the module, everything should be wired up by default.If you need to customize any aspect of the source or config, you can override and register it with the Dependency Injection module.
Code: Wiring up a custom Model Source
import { AsyncContext } from '@travetto/context';
import { InjectableFactory } from '@travetto/di';
import { SQLModelService, SQLModelConfig } from '@travetto/model-sql';
import { SqliteDialect } from '@travetto/model-sqlite';
export class Init {
@InjectableFactory({ primary: true })
static getModelService(ctx: AsyncContext, conf: SQLModelConfig) {
return new SQLModelService(ctx, conf, new SqliteDialect(ctx, conf));
}
}
where the SQLModelConfig is defined by:
Code: Structure of SQLModelConfig
import { Config } from '@travetto/config';
import { asFull } from '@travetto/runtime';
/**
* SQL Model Config
*/
@Config('model.sql')
export class SQLModelConfig<T extends {} = {}> {
/**
* Host to connect to
*/
host = '127.0.0.1';
/**
* Default port
*/
port = 0;
/**
* Username
*/
user = '';
/**
* Password
*/
password = '';
/**
* Table prefix
*/
namespace = '';
/**
* Database name
*/
database = 'app';
/**
* Auto schema creation
*/
autoCreate?: boolean;
/**
* Db version
*/
version = '';
/**
* Raw client options
*/
options: T = asFull({});
}
Additionally, you can see that the class is registered with the @Config annotation, and so these values can be overridden using the standard Configuration resolution paths.