Socket
Socket
Sign inDemoInstall

aca.ts

Package Overview
Dependencies
Maintainers
2
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aca.ts

Aca.ts is a CLI based on Typescript and Knex.js. It can automatically sync database schema, automatically generate APIs for accessing the database, automatically create frontend APIs through backend functions (like RPC).


Version published
Weekly downloads
5
decreased by-92.06%
Maintainers
2
Weekly downloads
 
Created
Source

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) and can run on node.js runtime, 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

  1. Create an aca project:
$ aca create <projectName> & cd <projectName>
  1. Open .aca directory, copy your custom ORM file into the directory, and add this file name to config.json/orm field.
  1. 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
  1. 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

Keywords

FAQs

Package last updated on 06 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc