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): support atomic updates via raw() helper #4094

Merged
merged 1 commit into from Mar 19, 2023
Merged

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented Mar 4, 2023

When you want to issue an atomic update query via flush, you can use the static raw() helper:

const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush

The raw() helper returns special raw query fragment object. It disallows serialization (via toJSON) as well as working with the value (via valueOf()). Only single use of this value is allowed, if you try to reassign it to another entity, an error will be thrown to protect you from mistakes like this:

order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized

Closes #3657

@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (a0a77bc) 99.56% compared to head (e59ac74) 99.57%.

Additional details and impacted files
@@           Coverage Diff           @@
##               v6    #4094   +/-   ##
=======================================
  Coverage   99.56%   99.57%           
=======================================
  Files         217      217           
  Lines       13945    14006   +61     
  Branches     3190     3213   +23     
=======================================
+ Hits        13885    13947   +62     
+ Misses         56       55    -1     
  Partials        4        4           
Impacted Files Coverage Δ
packages/core/src/utils/Utils.ts 99.79% <ø> (+0.60%) ⬆️
packages/knex/src/SqlEntityManager.ts 100.00% <ø> (ø)
packages/core/src/typings.ts 100.00% <100.00%> (ø)
...ckages/core/src/unit-of-work/ChangeSetPersister.ts 100.00% <100.00%> (ø)
packages/core/src/utils/QueryHelper.ts 100.00% <100.00%> (ø)
packages/knex/src/AbstractSqlDriver.ts 100.00% <100.00%> (ø)
packages/knex/src/AbstractSqlPlatform.ts 100.00% <100.00%> (ø)
packages/knex/src/query/CriteriaNodeFactory.ts 100.00% <100.00%> (ø)
packages/knex/src/query/QueryBuilder.ts 99.51% <100.00%> (-0.01%) ⬇️
packages/knex/src/query/QueryBuilderHelper.ts 99.76% <100.00%> (-0.24%) ⬇️

... and 5 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

```ts
const ref = em.getReference(User, 1);
ref.age = raw(`age * 2`);
await em.flush();
console.log(ref.age); // real value is available after flush
```

Closes #3657
@B4nan B4nan merged commit af467b4 into v6 Mar 19, 2023
8 checks passed
@B4nan B4nan deleted the raw-uow-updates branch March 19, 2023 22:59
B4nan added a commit that referenced this pull request Mar 19, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Apr 6, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Apr 10, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Apr 12, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Apr 26, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
jsprw pushed a commit to jsprw/mikro-orm-full-text-operators that referenced this pull request May 7, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes mikro-orm#3657
jsprw added a commit to jsprw/mikro-orm-full-text-operators that referenced this pull request May 7, 2023
B4nan added a commit that referenced this pull request May 14, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request May 14, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request May 24, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request May 26, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Jun 11, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Sep 10, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Sep 20, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Sep 24, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Sep 30, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
@B4nan B4nan mentioned this pull request Sep 30, 2023
22 tasks
B4nan added a commit that referenced this pull request Oct 2, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Oct 17, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Oct 21, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Oct 25, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Nov 2, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
B4nan added a commit that referenced this pull request Nov 5, 2023
When you want to issue an atomic update query via flush, you can use the
static `raw()` helper:

```ts
const ref = em.getReference(Author, 123);
ref.age = raw(`age * 2`);

await em.flush();
console.log(ref.age); // real value is available after flush
```

The `raw()` helper returns special raw query fragment object. It
disallows serialization (via `toJSON`) as well as working with the value
(via
[`valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)).
Only single use of this value is allowed, if you try to reassign it to
another entity, an error will be thrown to protect you from mistakes
like this:

```ts
order.number = raw(`(select max(num) + 1 from orders)`);
user.lastOrderNumber = order.number; // throws, it could resolve to a different value
JSON.stringify(order); // throws, raw value cannot be serialized
```

Closes #3657
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.

None yet

2 participants