JSPM

  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q76002F
  • License MIT

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

Package Exports

  • @travetto/model-postgres
  • @travetto/model-postgres/__index__.ts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@travetto/model-postgres) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

PostgreSQL Model Service

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

Install: @travetto/model-postgres

npm install @travetto/model-postgres

# or

yarn add @travetto/model-postgres

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

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

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

where the SQLModelConfig is defined by:

Code: Structure of SQLModelConfig

@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.