OxL Справочник OxL
РусскийEnglish

error atomic-db-effects

error Стандарт: [§11.2]

Тело atomic(db) использует эффект, кроме db (net, io).

What it means#

The body of atomic(db) { ... } is a database transaction that is re-run on a serialization conflict (up to DB_TX_RETRIES times). Only the db effect (and emit, which goes through the outbox and is published after the commit) is allowed inside it; a call with net or io could be repeated or could show a state that is never committed (§11.2). A call to a function whose effects include io or net counts too. Effects of other databases are not distinguished by this implementation (determined by the implementation, D-7790).

Example#

oxl✓ проверяется в CI
use std.orm { Db }

@table("orders")
data Order {
  @pk id: i64
  userId: u64
}

fn place(db: Db, o: Order) db, io {
  atomic(db) {
    db.insert(o)
    print("saved")             // <- atomic-db-effects
  }
}
error
atomic-db-effects

How to fix#

Do the side effect before or after the transaction, or publish an event with emit (it is sent after the commit).

oxl✓ проверяется в CI
use std.orm { Db }

@table("orders")
data Order {
  @pk id: i64
  userId: u64
}

data OrderEvent {
  orderId: i64
}

topic OrderEvents: OrderEvent

cluster demo {
  role store { journal }
}

fn place(db: Db, o: Order) db, io {
  atomic(db) {
    db.insert(o)
    emit OrderEvents(OrderEvent{ orderId: o.id })
  }
  print("saved")
}

See also#

OxL 1.0.0-beta · Версия документации 1.0.0-beta© OxwaldLink · сгенерировано из Стандарта, исходников std и руководства