Object Relation Mapper for SQL Database. Flexible and Strong
npm install taichi-orm

Tai Chi (太極)
Emphasis on both hard and soft
A new way to deal with your Data Logic of SQL Databse. You can define a virtual field called ComputeProperty (that actually is SQL statement) for a data model.
- The common data logics in form of ComputeProperty of Data Model become more reusable.
- The codes of data query become more human readable because complex data logics can be abstracted in ComputeProperty.
- Flexible and strong Model API. Without using QueryBuilder, Model.find() is powerful enough to build complex logics by extending or modifying the ComputeProperty.
- Developed in Typescript but you can use it without typescript compiler.
- Common relation logics such as HasMany and belongsTo are can be defined in form of ComputeProperty. And the related Models are queried in one single Sql call.
Imagine an E-commerce system. A product (Model) has various fields like availableStart, availableEnd and remainingStock.
A product is active when the current time are within these dates and the remainingStock are not zero.
We can define the schema like below (with a isActive ComputeProperty).ComputeProperty consist of ComputeFunction that defines how to make a SQL value (we called Scalar).
The variable parent represents the Datasource of Product Model.
The property isActive combines the values of other FieldProperty.
``ts
export default class Product extends Model {
//define field properties here
id = this.field(PrimaryKeyType)
availableStart = this.field(DateNotNullType)
availableEnd = this.field(DateNotNullType)
remainingStock = this.field(NumberNotNullType)
//define ComputeProperty based on the value of FieldProperty
isActive = Product.compute((parent) => {
return new Scalar
parent.$.availableStart.lessThan( new Date() ),
parent.$.availableEnd.greaterThan( new Date() ),
parent.$.remainingStock.greaterThan(0)
))
})
}
`
Below the ModelRepository.find() function accepts one argument FindOptions (Just like the other ORM). where
The part specifies the data filtering condition.isActive
You can use the ComputeProperty simply just like a normal field (FieldProperty) in the where object.`ts`
let activeProducts = await Product.find({
where: {
isActive: true
}
})
If you are interested and agreed with the ideas, you may join our project. You can talk in the discussion board.
`bash
git clone ...
``