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

feat(core): refactor merging to allow querying by custom type #800

Merged
merged 1 commit into from Sep 1, 2020

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented Sep 1, 2020

This changes internal mechanism of em.merge(). Originally it was using
EntityAssigner inside em.merge() together with UoW.merge(), which
was called twice. Because of this, the custom types were processed multiple
times, and the value passed to conversion method was often already converted.

Now we use only the Hydrator for this. As a sideproduct of those changes,
we can now query by custom types.

class UuidBinaryType extends Type<string, Buffer> {

  convertToDatabaseValue(value: string): Buffer {
    return Buffer.from(parse(value));
  }

  convertToJSValue(value: Buffer): string {
    return stringify(value);
  }

  getColumnType(): string {
    return 'binary(16)';
  }

}

@Entity()
class A {

  @PrimaryKey({ type: UuidBinaryType })
  id: string = v4();

}

const a = await em.find(A, { id: '...' });

Closes #739

This changes internal mechanism of `em.merge()`. Originally it was using
`EntityAssigner` inside `em.merge()` together with `UoW.merge()`, which
was called twice. Because of this, the custom types were processed multiple
times, and the value passed to conversion method was often already converted.

Now we use only the `Hydrator` for this. As a sideproduct of those changes,
we can now query by custom types.

```typescript
@entity()
class A {

  @PrimaryKey({ type: UuidBinaryType })
  id: string = v4();

}

const a = await em.find(A, { id: '...' });
```

Closes #739
@B4nan B4nan merged commit bfbc5f8 into master Sep 1, 2020
@B4nan B4nan deleted the custom-type-params branch September 1, 2020 18:48
@B4nan B4nan mentioned this pull request Sep 1, 2020
46 tasks
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 this pull request may close these issues.

Querying with custom types
1 participant