@travetto/model-mysql

4.0.7 • Public • Published

MySQL Model Service

MySQL backing for the travetto model module, with real-time modeling support for SQL schemas.

Install: @travetto/model-mysql

npm install @travetto/model-mysql

# or

yarn add @travetto/model-mysql

This module provides a MySQL-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:

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 { MySQLDialect } from '@travetto/model-mysql';

export class Init {
  @InjectableFactory({ primary: true })
  static getModelService(ctx: AsyncContext, conf: SQLModelConfig) {
    return new SQLModelService(ctx, conf, new MySQLDialect(ctx, conf));
  }
}

where the SQLModelConfig is defined by:

Code: Structure of SQLModelConfig

import { Config } from '@travetto/config';

/**
 * 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 = {} as T;
}

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.

Package Sidebar

Install

npm i @travetto/model-mysql

Homepage

travetto.io

Weekly Downloads

0

Version

4.0.7

License

MIT

Unpacked Size

12.8 kB

Total Files

7

Last publish

Collaborators

  • arcsine