English | 简体中文
Aca.ts
Aca.ts is a node.js CLI based on Typescript and Knex.js. It can automatically sync database schema according to a custom ORM. It can also automatically generate APIs for accessing the database. More importantly, it can automatically create frontend APIs through backend functions and the generated database APIs (like RPC), so frontend developers can easily access the backend without defining routing. The APIs are typescript, and therefore the tips are very friendly when coding.
Use the class syntax of Typescript to define ORM:
- Define a root namespace to represent your database
- Define a table with a class (class name as table name)
- Define a column or a relationship with a class property (property name as column name)
- Add constraints to a table or a column with decorators
An example could be found below:
example-blog.ts
namespace db {
export class user {
id: id
@$_.unique name: string
age?: int
married = false
profile?: profile
posts: post[]
}
export class profile {
id: id
password: string
@$_.foreign('userId') user: user
}
export class post {
id: id
content: string
score: float
@$_.foreign('userId') user: user
categories: category[]
}
export class category {
id: id
name: string
@$_.foreign('categoryId') parent?: category
children: category[]
posts: post[]
}
}
Install
npm install -g aca.ts
Usage
- Create an aca project:
$ aca create <projectName>
$ cd <projectName>
- Open .aca directory, copy your custom ORM file into the directory, and add this file name to config.json/orm field.
- Use the following method to create aca.ts apps:
Create a backend app (a simple koa framework):
$ aca server
Create a frontend app (a react app with create-react-app):
$ aca client
Add self built app to the project:
$ aca add <appName> --server --client --apiDir <path>
path default: src/aca.server src/aca.client
- Generate api
$ aca up
Then the database, frontend (if necessary), and backend are all set up, you can start your project now. Happy coding!
The generated backend APIs usage example are as follows:
The generated frontend APIs usage example are as follows:
Supported databases for now:
- PostgreSQL
- MSSQL
- Better-Sqlite3