manyuanrong / dso

Simple Orm library for Deno based on deno_mysql

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

model optional chaining operator, tsconfig, & where clause in documentation

vmasdani opened this issue · comments

Hi. There are a few things I want to address here about the documentation in README, maybe I can help with adding to the documentation.

  • Adding optional chaining operator to model fields
  • Defining tsconfig for decorators
  • Where clause

Adding optional chaining operator to model fields
I get an error when I follow the README by defining models like this:

@Model("users")
class UserModel extends BaseModel {
  @Field({
    type: FieldType.INT,
    primary: true,
    length: 11,
    autoIncrement: true
  })
  id: number;

  @Field({ type: FieldType.STRING, length: 30 })
  name: string;

  @Field({ type: FieldType.STRING, length: 30 })
  password: string;
}

I have to define the optional chaining operator (? and !) in order to make it work

@Model("users")
class UserModel extends BaseModel {
  @Field({
    type: FieldType.INT,
    primary: true,
    length: 11,
    autoIncrement: true
  })
  id!: number;

  @Field({ type: FieldType.STRING, length: 30 })
  name?: string;

  @Field({ type: FieldType.STRING, length: 30 })
  password?: string;
}

Defining tsconfig for decorators
In older issue I found that a tsconfig.json must be added

{
  "compilerOptions": {
    "allowJs": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "esnext"
  }
}

and deno must be run in such a way in order for it to work: #6

deno run -A -c tsconfig.json main.ts

But it's not included in the documentation.

Where clause documentation
I couldn't find example using the Where clause in dso API functions for instance findAll and findOne, maybe if you give me an example code I can help write in the documentation.

In summary

I can help adding to the documentation by making PR regarding adding optional chaining operator to models and also regarding tsconfig, but I need examples regarding Where clause since I can't figure it out and I can't find any example codes in tests etc.

How to construct Where conditions, more examples can be found here
https://github.com/manyuanrong/sql-builder

Welcome to submit PR