tydet-core-mysql
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

TyDeT Core MySQL

TyDeT Core MySQL is a Typescript & Javascript library for TyDeT Core to handle a connection to a MySQL database.

TyDeT (Typescript Developer Tools) Core MySQL is a module for TyDeT Core to handle a connection with a MySQL Database and managing the entities, validations, migrations and other tools.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

npm install tydet-core tydet-core-mysql

It is required to install TyDeT Core to use this module.

Usage

Basic usage

import { Context } from 'tydet-core';
import { MysqlConnector, MysqlEntity, QueryFind } from 'tydet-core-mysql';

// Add connector as Service
let app = new Context()
let mysql = new MysqlConnector()
await app.mountService("mysql", mysql)

// Execute queries
let query = QueryFind(mysql, "users", {firstName: "My name"})
let data = await mysql.run(query)

// Define entities
class User extends MysqlEntity {
  id: number
  firstName: string
  lastName: string
}

User.DefineSchema("users", {
  id: {
    type: MysqlDataType.INT,
    primaryKey: true
  },
  firstName: {
    type: MysqlDataType.VARCHAR,
    required: true
  },
  lastName: MysqlDataType.VARCHAR
})

class Comment extends MysqlEntity {
  id: number
  message: string
  userId: number
  createdAt: Date

  user?: User
}

Comment.DefineSchema("comments", {
  id: {
    type: MysqlDataType.INT,
    primaryKey: true
  },
  message: {
    type: MysqlDataType.VARCHAR,
    required: true
  },
  userId: MysqlDataType.INT,
  createdAt: {
    type: MysqlDataType.DATETIME,
    default: MysqlDefaultValue.NOW
  }
})

User.hasMany(Comment, "userId")
Comment.belongsTo(User, "userId", "user")

let users = await User.Find(mysql, {firstName: "My name"})

Check the docs for more details about the service.

Changelog

Learn about the latest improvements.

License

MIT License.

Contributing

We'd love for you to contribute to TyAPI Core Mysql and help make it even better than it is today! Find out how you can contribute here.

Dependencies (6)

Dev Dependencies (9)

Package Sidebar

Install

npm i tydet-core-mysql

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

395 kB

Total Files

40

Last publish

Collaborators

  • kabany