The type of the Entity
The type of the Entity
The Entity
's Id type
The Entity
's Id type
CrudActions.Model is the Entity
in this context
CrudActions.Model is the Entity
in this context
Before insert interceptor method.
Before insert interceptor method. This method is called just before record insertion. The default implementation returns a successful DBIO wrapping the passed entity.
The returned DBIOAction
is combined with the final insert DBIOAction
and 'marked' to run on the same transaction.
Override this method if you need to add extract validation or modify the entity before insert.
See examples bellow:
// simple validation example override def beforeInsert(foo: Foo)(implicit exc: ExecutionContext): DBIO[Foo] = { if (foo.name.trim.isEmpty) { DBIO.failed(new RuntimeException("Name can't be empty!!!") } else { DBIO.successful(foo) } }
// simple audit example override def beforeInsert(foo: Foo)(implicit exc: ExecutionContext): DBIO[Foo] = { // ensure that created and lastUpdate fields are updated just before insert val audited = foo.copy(created = DateTime.now, lastUpdate = DateTime.now) DBIO.successful(audited) }
Before update interceptor method.
Before update interceptor method. This method is called just before record update. The default implementation returns a successful DBIO wrapping the passed entity.
The returned DBIOAction
is combined with the final update DBIOAction
and 'marked' to run on the same transaction.
Override this method if you need to add extract validation or modify the entity before update.
See examples bellow:
// simple validation example override def beforeUpdate(id: Int, foo: Foo)(implicit exc: ExecutionContext): DBIO[Foo] = { findById(id).flatMap { oldFoo => if (oldFoo.name != foo.name) { DBIO.failed(new RuntimeException("Can't modify name!!!") } else { DBIO.successful(foo) } } }
// simple audit example override def beforeUpdate(id: Int, foo: Foo)(implicit exc: ExecutionContext): DBIO[Foo] = { // ensure that lastUpdate fields are updated just before update val audited = foo.copy(lastUpdate = DateTime.now) DBIO.successful(audited) }
Returns total table count
Returns total table count
Delete a Model
.
Delete a Model
.
DBIO[Int] with the number of affected rows
Delete a Entity
by Id
Delete a Entity
by Id
DBIO[Int] with the number of affected rows
Fetch all elements from a table.
Fetch all elements from a table.
- the number of row to fetch, defaults to 100
StreamingDBIO[Seq[Model], Model]
Finds Entity
referenced by Id
.
Finds Entity
referenced by Id
.
May fail if no Entity
is found for passed Id
DBIO[Entity] for the Entity
Finds Entity
referenced by Id
optionally.
Finds Entity
referenced by Id
optionally.
DBIO[Option[Entity]] for the Entity
Insert a new Entity
Insert a new Entity
DBIO[Id] for the generated Id
Insert or Update a Model
Insert Model
if not yet persisted, otherwise update it.
Insert or Update a Model
Insert Model
if not yet persisted, otherwise update it.
DBIO[Model] for a Model
as persisted in the table.
Update a Model
.
Update a Model
.
DBIO[Model] for a Model
as persisted in the table.