Code Monkey home page Code Monkey logo

Comments (12)

Bnaya avatar Bnaya commented on May 14, 2024 4

ok, this just worked for me in the entity level:

  @PrimaryColumn({
    name: "bt_brand_id",
    length: 20,
    type: "varchar",
  })
  public id!: string;

But if there's a way on the that lib level, i think i will prefer it

from crud.

michaelyali avatar michaelyali commented on May 14, 2024 3

Shipped with v3.0.0

from crud.

michaelyali avatar michaelyali commented on May 14, 2024 2

I think it's possible. We already have params in CrudOptions object, where you can map id path param to an entity's field. But some adjustment in RepositoryService is needed in that case. I'll try to do this ASAP. Cheers!

from crud.

NotAmaan avatar NotAmaan commented on May 14, 2024 2

Valid point by @dhaspden
@nestjsx/crud assumes the id column to be a number in both the CrudController.getOneBase and RepositoryService.getOne

We rarely use the type number as an ID type of entities which are available to public to avoid making the total number of records in our database easy to discover.

from crud.

dhaspden avatar dhaspden commented on May 14, 2024 1

I took a look briefly at this since I was also interested in having this. I think it might be a bit more nuanced because a lot of places assume number type for the identifier field (CrudController and the decorators which setup parsing the parameter to a number.)

I was trying to think about how we could use the params in CrudOptions and figured it might be unintuitive to map them somehow to the service since you could potentially have more than one attribute in that params option. I wonder if maybe a new RestfulOptions, maybe like idColumnName would make more sense.

This leads me to another nuance which is handling the case where this id column isn't a number but instead something like a UUID. We would need a way to specify the type of that identifier field. I'm no expert on Typescript (yet) but perhaps that could be solved with yet another option, say idColumnType? I'm not sure if it'd work but you could also make the service a two value generic where T is the entity type and U is the type of the key?

Sorry about puking my thoughts out on the page but hopefully that gets through. I'd be really interested in seeing this happen since I like to have uuid columns for my public facing API to avoid having to disclose internal database ids.

Edit

If you set the params object to be

{
  id: 'uuid'
}

For example, would the library process that correctly? If so I guess we could technically parse the identifier something along the lines of

const idFieldName = params && params.id ? params.id : 'id';

D

from crud.

netremo avatar netremo commented on May 14, 2024 1

+1: id should be type string as option (UUID)

from crud.

niuba avatar niuba commented on May 14, 2024 1

...createParamMetadata(RouteParamtypes.PARAM, 0, [setParseIntPipe()], 'id'),

change to createParamMetadata(RouteParamtypes.PARAM, 0, [], 'id'),

from crud.

Bnaya avatar Bnaya commented on May 14, 2024

Thank you!

from crud.

niuba avatar niuba commented on May 14, 2024

+1: id should be type string as option (UUID)

from crud.

Bnaya avatar Bnaya commented on May 14, 2024

Thank you very much

from crud.

Bnaya avatar Bnaya commented on May 14, 2024

Ok,
I'm not sure how to use it XD
I want the name of the id field to be brand_id

from crud.

chriszrc avatar chriszrc commented on May 14, 2024

I can now do just this:

@PrimaryGeneratedColumn({
        type:"integer",
        name:"population_id"
        })
    population_id:number;

and it's working-

from crud.

Related Issues (20)

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.