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

Allow setting custom RoowKey values #21

Closed
manekinekko opened this issue Oct 11, 2019 · 3 comments
Closed

Allow setting custom RoowKey values #21

manekinekko opened this issue Oct 11, 2019 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@manekinekko
Copy link
Collaborator

This would be simple to add. Here are the steps:

  1. Update https://github.com/nestjs/azure-database/blob/master/lib/table-storage/azure-table.repository.ts#L107 to:
async create(entity: T, rowKeyValue?: string): Promise<T> {
  1. Update https://github.com/nestjs/azure-database/blob/master/lib/table-storage/azure-table.repository.ts#L110 to:
entity = AzureEntityMapper.createEntity<T>(entity, rowKeyValue );
  1. update specs files.
@manekinekko manekinekko added enhancement New feature or request good first issue Good for newcomers labels Oct 11, 2019
@tabs-not-spaces
Copy link
Contributor

Doing this now, but even if we include rowKeyValue into the create function, the static createEntity in https://github.com/nestjs/azure-database/blob/master/lib/table-storage/azure-table.mapper.ts#L36 needs to be updated as well, yes? otherwise it's just going to replace rowKeyValue with a GUID...

@tabs-not-spaces
Copy link
Contributor

tabs-not-spaces commented Oct 12, 2019

my other thought was simply modifying

static createEntity<D>(partialDto: Partial<AzureEntityMapper>, rowKeyValue = generateUuid()) {
to

static createEntity(partialDto, rowKeyValue) {

and updating

entityDescriptor.RowKey._ = rowKeyValue;
to:

 if (null == partialDto.RowKey) {
      entityDescriptor.RowKey._ = rowKeyValue
  }
  else {
      entityDescriptor.RowKey._  = partialDto.RowKey;
  }

This way, we can define a RowKey in the entity / DTO which will take precedence, or if we don't implicitly define a RowKey a GUID will be created.


Update: looks like we were both on the same correct path - there were a few extra changes required. Submitting PR now :)

@manekinekko
Copy link
Collaborator Author

manekinekko commented Oct 14, 2019

closed in 070bad3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants