an instance of the CodeToSql class, providing information about T to guide the SQL construction
a data mapper to convert the RowData to the entity object (T)
the sql used for updating the table
the sql used for inserting new rows in the table, using the default identity (usually a primary key) (usually a generated from a postgres Sequence)
the sql needed to insert rows when the inserted object is providing the identity
a function to produce a copy of the Entity (T) with the identity replaced
an instance of the CodeToSql class, providing information about T to guide the SQL construction
a function to produce a copy of the Entity (T) with the identity replaced
Deletes the entity with the specified id
Deletes the entity with the specified id
the identity of the row containing the Entity (T)
implicit configuration to use
returns a QueryResult, but really it is expected the result is used just to ensure the delete has been performed before continuing
Example:
async { await(superHeroAccess.delete(1)) // ignoring return, but code after this point will be continued once delete is performed }
Gets the Entity (T) with the specified id.
Gets the Entity (T) with the specified id. If it doesn't exist None is returned.
the identity of the row containing the Entity (T)
implicit configuration to use
returns Some(Entity) or None if it doesn't exist
Example:
async { val hero = await(superHeroAccess.get(2)) println hero.get.name }
Inserts the entity into the database, where a specific value for the identity column is provided.
Inserts the entity into the database, where a specific value for the identity column is provided.
the entity to be updated, the id column must not exist in the database yet
info for configuration
the inserted entity. The inserted row isn't retrieved from the database, so any db calculated values won't have changed
Example:
val wonderWoman = SuperHero(666, "Wonder Woman", true) superHeroAccess.identityInsert(wonderWoman)
the sql needed to insert rows when the inserted object is providing the identity
Inserts the entity into the database.
Inserts the entity into the database. This uses the database default for the id column, which is typically auto generated from some Postgres Sequence.
the entity to be updated, the value in the id is ignored
the implicit configuration info
the entity with its new id. The inserted row isn't retrieved from the database, so any db calculated values (apart from the identity) won't be changed
Example:
async { val catwoman = SuperHero(0, "Catwoman") val insertedCatwoman = await( superHeroAccess.insert(catwoman) ) val loadedCatwoman = await( superHeroAccess.load(insertedCatwoman.superHeroId )) }
the sql used for inserting new rows in the table, using the default identity (usually a primary key) (usually a generated from a postgres Sequence)
Loads the Entity from the underlying table.
Loads the Entity from the underlying table. The entity is expected to exist, if not throws an exception.
the identity of the row containing the Entity (T)
implicit configuration to use
the Entity
Example:
async { val hero = await(superHeroAccess.load(2)) println hero.name val BANG = await(superHeroAccess.load(-123)) // would throw exception assuming not -123 exists! }
a data mapper to convert the RowData to the entity object (T)
Updates the specified entity
Updates the specified entity
the entity to be updated
implicit configuration info
the update entity, this isn't retrieved from the database, so any db calculated columns won't have been updated
Example:
async { val hero = await( superHeroAccess.load(1) ) superHeroAccess.update( hero.copy(wearsTights = true) ) }
the sql used for updating the table
TableAccess lets you easily implement a 'Table Data Gateway' as per Fowler PoEAA
Example:
The above code creates a Table Data Gateway to access the SuperHeroes.
Each SuperHero is represented by a row in the table 'super_hero'.
The DbCodeGenerator is a Scala Macro based class which builds data mappers based on the names of the Entity object SuperHero. The generated code can be replaced by hand crafted SQL where needed.
Once you have the SuperHeroAccess you can used standard CRUD activities on the SuperHeroes. For example:
for a full example, see the sample in the test package of this project.
Using a Table Data Gateway is great for testing, it makes it very simple to mock out the database access.
the type of the Entity object the TableAccess is providing access to