typescript-mysql-model

{ "version": "1.12.0", "name": "typescript-mysql-model", "description": "", "main": "index.js", "types": "index.d.ts", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url":


Keywords
typescript, mysql, orm, generate, class, interface
License
MIT
Install
npm install typescript-mysql-model@1.8.1

Documentation

typescript-mysql-model

npm version Dependencies Status

This is an attempt to auto generate a boilerplate for projects using TypeScript in combination with MySql. Generating interfaces and ORM-like sturctures allowes the IDE to provide auto-completion and compile time error handling. This project relies heavily on Knex

Installation

$ npm install typescript-mysql-model --save

Examples

Just initalize with a knex instance and call respective function to start generating.

import { TsBuilder } from "typescript-mysql-model"
import * as Knex from "knex"

// Create a knex instance
var knex = Knex({
  client: 'mysql',
  connection: {
    host: 'ensembldb.ensembl.org',
    user: 'anonymous',
    password: '',
    database: 'takifugu_rubripes_core_82_4',
  },
});

async function build() {
  // init and call respective function with a folder that exists
  let tsBuilder = await new TsBuilder().init(knex)
  tsBuilder.renderClassFiles('./db/inserter/')
  tsBuilder.renderInserter('./db/inserter/')
  tsBuilder.renderTableFile('./db/')
  tsBuilder.renderViewFile('./db/')
  tsBuilder.renderStoredProcedure('./db/')
  knex.destroy()
}

build()

Example

Sample project

License

MIT