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.
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.
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.
Learn about the latest improvements.
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.