GithubHelp home page GithubHelp logo

blaanteam / ts-sql-builder Goto Github PK

View Code? Open in Web Editor NEW
8.0 8.0 0.0 153 KB

SQL query & schema generator for Node.js

Home Page: https://www.npmjs.com/package/ts-sql-builder

License: MIT License

TypeScript 100.00%

ts-sql-builder's People

Contributors

os-moussao avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ts-sql-builder's Issues

Separate Concerns

Issue Type

enhancement

Description

Seperate code in /lib/query-builder.ts

  • put interfaces & enums in different files
  • move createQueryBuilder() to functions

Add tests & examples

Issue Type

enhancement

Description

Add unit & e2e tests, as well as usage examples

Add schema builder

Is your feature request related to a problem? Please describe.

It's a better idea to create an automated schema builder.

Describe the solution you'd like

Kind of like ORMs (typeorm entities for instane), I'd like to automatically generate sql table schemas just from a class. This way, when I fetch data from a table I know for sure it can fit into a class (from which I generated the table schema).

Describe alternatives you've considered

None, the main solution seems doable & perfect!

Additional context

Idea:
This code:

@Table('users')
class User {
  @PrimaryKey()
  @Column({ type: 'SERIAL' })
  id!: number;

  @Column({ type: 'VARCHAR(255)', nullable: false })
  name!: string;

  @Column({ type: 'VARCHAR(65)', nullable: false, unique: true })
  username!: string;

  @Column({ type: 'INTEGER', check: 'age >= 18' })
  age!: number;

  @Column({ type: 'VARCHAR(255)', unique: true })
  email!: string;

  @Column({
    name: 'created_at',
    type: 'TIMESTAMP',
    default: () => 'CURRENT_TIMESTAMP',
  })
  createdAt!: Date;

  @Column({ type: 'BOOLEAN', default: true })
  activated!: boolean;
}

Generates this schema:

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  name VARCHAR(255) NOT NULL,
  username VARCHAR(65) UNIQUE NOT NULL,
  age INTEGER CHECK (age >= 18),
  email VARCHAR(255) UNIQUE,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  activated BOOLEAN DEFAULT true
);

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

npm
package.json
  • nodemon ^3.0.2
  • ts-node ^10.9.2

  • Check this box to trigger a request for Renovate to run again on this repository

Add documentation

Issue Type

Docs

Description

  • Add README.md
  • Add JSDoc comments
  • Generate documentation (may use typedoc for that)

Example

  /**
   * Add columns to the SELECT clause of the SQL query.
   * @param selection A column name, a record of columns-aliases, or an array containing a mix both.
   * @param fromTable Optional. If specified, all selected columns are prefixed with 'fromTable.'.
   * @returns The current instance of the QueryBuilder for method chaining.
   */
  select(...)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.