MyNodeORM
A full-fledged ORM framework for NodeJS and MySQL with develop friendly code aimed to handle database migrations, MySQL Query builder / helper and property mapping.
Installation
Use the npm package manager to install "MySQL Query Builder" by running the command
npm install @nyffels/mynodeorm
Usage
Map a class to a MySQL table
You need to map your class to a MySQL table and columns to use them in the QueryBuilder function. A mapping happens partial on class level and partial on property level. \
Class decorators
The @id decorator will allow the developer to fetch the class by it's id.
Key: string: This parameter is the ID used to link the string to a class
Class: object: this Object is the class itself declared under this decorator
@id(Key, Class)
The @table decorator contains the name of the table that is linked to this class.
mySqlTableName: string: This includes the MySQL table name linked to this class and will be used in the QueryBuilder
@table(mySqlTableName)
Property decorators
The @column decorator contains the name of the column that is linked to this property.
mySqlColumnName: string: This includes the MySQL column name linked to this property and will be used in the QueryBuidler
@column(mySqlColumnName)
The @type decorator contains the type of the column. If @type is missing of invalid the type will default to a string.
propertyType: number | boolean | date | datetime | string: The decorator contains information about the column type. For all the non-string values it is best practice to declare the types to be 100% certain on SQL generation.
@type(propertyType)
Example:
@id("exWork", WorkClass)\
@table("Ex_work")\
export class WorkClass {
@column("workStart")
@type("datetime")
start: Date;
@column("workEnd")
@type("datetime")
end: Date;
constructor() {}
}
Query Builder
TODO documentation
Standalone functions
MySQL Connections
setConnection()
TODO documentation
getConnection(skipNoConnectionError = true)
TODO documentation
endConnection()
TODO documentation
Query handling
doMutation(sqlQuery: string, options: QueryOptions | null = null)
TODO documentation
doQuery<T = any>(sqlQuery: string, options: QueryOptions | null = null)
TODO documentation
queryResultToObject<T = any>(classObject: Object, results: any[])
TODO documentation
Value parsers
parseString(value: string)
TODO documentation
parseNumber(value: number)
TODO documentation
parseBoolean(value: boolean, canBeNull = false)
TODO documentation
parseDate(date: Date, time = false)
TODO documentation
parseValue(sourceClass: any, property: string, value: any)
TODO documentation
Database Migration
Currently not available in the framework. This function will be released in a newer version.
Progress
Contributing
Pull requests are welcome but open an issue first to discuss what you would like to change.
For major changes, please open an issue first to discuss what you would like to change.
License
MIT - Copyright (c) 2023-2024 Nyffels BV
Links
github (https://github.com/Nyffels-Open-Source/mysql-query-builder)
npmjs (https://www.npmjs.com/package/@nyffels/mysql-query-builder)
Dependencies
Release notes
Currently in Alpha development with possible breaking changes. Use this software at your own risk. Nyffels doesn't provide Release notes or changelogs at this stage of development.