Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ID field #46

Closed
dalssoft opened this issue Aug 31, 2021 · 8 comments · Fixed by #52
Closed

ID field #46

dalssoft opened this issue Aug 31, 2021 · 8 comments · Fixed by #52

Comments

@dalssoft
Copy link
Member

In order to improve metadata about which fields represent the IDs of an entity it would be possible to declare as field like:

const Customer = 
    entity('Customer', {
        id: id(Number),    <---- id definition
        name: field(String),
        isVIP() {
            ...
        }
    })

for composite IDs (ex: id + SSN):

const Customer = 
    entity('Customer', {
        id: id(Number),    <---- id definition
        SSN: id(Number),    <---- id definition
        name: field(String),
        isVIP() {
            ...
        }
    })

metadata:

Customer.prototype.meta.schema.id.isID //true
Customer.prototype.meta.schema.SSN.isID //true

This would help in:

  • CLI: better use case generation
  • 2Knex: better repository generation (no ID info required)
  • 2REST and 2GQL: better resolver code
@italojs
Copy link
Member

italojs commented Aug 31, 2021

1: I think this issue must to be opened into Gotu lib

2: Awesome ideia!

what do you think about we have an "uuid" type too?

const { field, id, UUID } = require('@herbs/herbs') // gotu

const Customer = 
    entity('Customer', {
        id: id(UUID),    <---- uuid id definition
        SSN: id(Number),  
        name: field(String),
        isVIP() {
            ...
        }
    })

@maikvortx
Copy link
Contributor

Its a better way to improve the metadata about entities.

@dalssoft dalssoft transferred this issue from herbsjs/buchu Sep 1, 2021
@dalssoft
Copy link
Member Author

dalssoft commented Sep 1, 2021

@italojs

what do you think about we have an "uuid" type too?

you can already use default for that.

const { field, id, UUID } = require('@herbs/herbs') // gotu

const Customer = 
    entity('Customer', {
        id: id(String, , { default: () => new UUID() }),    <---- uuid id definition
        
    })

@jhomarolo
Copy link
Contributor

I agree with @dalssoft, we already have this possibility with default.

@italojs
Copy link
Member

italojs commented Sep 15, 2021

this issue make match with this feature herbsjs/herbs2knex#23

@dalssoft
Copy link
Member Author

One more thing. the code below should have the same behavior:

const Customer = 
    entity('Customer', {
        id: id(Number),    <---- id definition
        ...
    })

And

const Customer = 
    entity('Customer', {
        id: field(Number, isID: true),    <---- id definition
        ...
    })

So id(...) is just a alias to field(..., isID:true)

@maikvortx
Copy link
Contributor

I agree with you @dalssoft!

@thgpdr thgpdr mentioned this issue Sep 25, 2021
4 tasks
jhomarolo added a commit to jhomarolo/gotu that referenced this issue Dec 8, 2021
Adding ID field option on metadata.

herbsjs#46
github-actions bot pushed a commit that referenced this issue Dec 12, 2021
# [1.1.0](v1.0.0...v1.1.0) (2021-12-12)

### Features

* **field:** add id field type ([d896b54](d896b54)), closes [#46](#46)
@jhomarolo
Copy link
Contributor

🎉 This issue has been resolved in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants