dineug / vuerd-vscode

ERD Editor vscode extension
https://marketplace.visualstudio.com/items?itemName=dineug.vuerd-vscode
MIT License
115 stars 14 forks source link

How to generate model classes from generated typescript types #94

Open guntribam opened 4 years ago

guntribam commented 4 years ago

First of all. Your product is amazing. Congratulations.

I need help understanding how can i use the generated code in Typescript to create my Model Classes.

I'll put an example right here: ERD This model create these two Typescript interfaces

export interface Conta {
  id: number;
  nome: string;
  idUsuario: number;
}
export interface Lancamento {
  id: number;
  valor: number;
  descricao: string | null;
  tipo: string;
  idConta: number;
}

But the model that i'm building is like this:

import { BaseModel, belongsTo, column, BelongsTo, hasMany, HasMany } from '@ioc:Adonis/Lucid/Orm'
import Lancamento from '../Lancamento'
import Usuario from 'App/Usuario/Usuario'

export default class Conta extends BaseModel {
  public static table = 'CONTA'

  @column({ isPrimary: true })
  id: number

  @column()
  nome: string

  @column({ columnName: 'idUsuario' })
  idUsuario: number

  @belongsTo(() => Usuario)
  usuario: BelongsTo<typeof Usuario>

  @hasMany(() => Lancamento, {foreignKey: 'idConta'})
  lancamentos: HasMany<typeof Lancamento>

}
import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm'

export default class Lancamento extends BaseModel{
  public static table = "LANCAMENTO"

  @column({ isPrimary: true })
  id: number

  @column()
  valor: number

  @column()
  descricao: string | null

  @column()
  tipo: string | null

  @column({ columnName: 'idConta' })
  idConta: number

}

How can i get the interfaces generated by the extension in order to create a class like these 2?

guntribam commented 4 years ago

I closed by mistake. Please open this project for funding. In some months i'll be able to help you guys with some money. Please accept it. Your work is great

dineug commented 4 years ago

I think we need detailed settings for various needs.

Or maybe we should develop an expanded API so that we can easily participate.

Like highlightjs.

I'm focusing on SQL DDL parser right now.

I'll think about it when it's done.

Thanks for letting me know your use case.

If you need it right now, Reference

Request a PR.

guntribam commented 4 years ago

I've never contributed to open source before, but i'll try to do something...

guntribam commented 4 years ago

I'll just leave here the prototype of how this can be achieved with a new canvas in this extension using Mustache as template. @dineug what do you think? Changes in Vuerd

dineug commented 4 years ago

Because the existing editor data is large enough, I think we need to externalize template data.