Skip to content

Commit

Permalink
RepoImpl are now classes (#68)
Browse files Browse the repository at this point in the history
objects are infinitely inflexible. users may want to extend the generated `Repo`s, and then you also need to extend the implementation.

It's also bad style to always code against the implementation, you should code to interface. In the case of typo, this leads you to testable code.
  • Loading branch information
oyvindberg authored Nov 14, 2023
1 parent 6c9a029 commit 24ef0fc
Show file tree
Hide file tree
Showing 573 changed files with 976 additions and 935 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object PersonRepoImpl extends PersonRepo {
class PersonRepoImpl extends PersonRepo {
override def delete(compositeId: PersonId)(implicit c: Connection): Boolean = {
SQL"""delete from compositepk.person where "one" = ${ParameterValue(compositeId.one, null, ToStatement.longToStatement)} AND "two" = ${ParameterValue(compositeId.two, null, ToStatement.optionToStatement(ToStatement.stringToStatement, ParameterMetaData.StringParameterMetaData))}""".executeUpdate() > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object FootballClubRepoImpl extends FootballClubRepo {
class FootballClubRepoImpl extends FootballClubRepo {
override def delete(id: FootballClubId)(implicit c: Connection): Boolean = {
SQL"""delete from myschema.football_club where "id" = ${ParameterValue(id, null, FootballClubId.toStatement)}""".executeUpdate() > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object MaritalStatusRepoImpl extends MaritalStatusRepo {
class MaritalStatusRepoImpl extends MaritalStatusRepo {
override def delete(id: MaritalStatusId)(implicit c: Connection): Boolean = {
SQL"""delete from myschema.marital_status where "id" = ${ParameterValue(id, null, MaritalStatusId.toStatement)}""".executeUpdate() > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object PersonRepoImpl extends PersonRepo {
class PersonRepoImpl extends PersonRepo {
override def delete(id: PersonId)(implicit c: Connection): Boolean = {
SQL"""delete from myschema.person where "id" = ${ParameterValue(id, null, PersonId.toStatement)}""".executeUpdate() > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import testdb.hardcoded.myschema.marital_status.MaritalStatusRow
import testdb.hardcoded.myschema.person.PersonId

class testInsert(random: Random) {
def compositepkPerson(name: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), one: Defaulted[Long] = Defaulted.UseDefault, two: Defaulted[Option[String]] = Defaulted.UseDefault)(implicit c: Connection): PersonRow = PersonRepoImpl.insert(new PersonRowUnsaved(name = name, one = one, two = two))
def myschemaFootballClub(id: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString)(implicit c: Connection): FootballClubRow = FootballClubRepoImpl.insert(new FootballClubRow(id = id, name = name))
def myschemaMaritalStatus(id: MaritalStatusId)(implicit c: Connection): MaritalStatusRow = MaritalStatusRepoImpl.insert(new MaritalStatusRow(id = id))
def myschemaPerson(favouriteFootballClubId: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString, nickName: Option[/* max 30 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), blogUrl: Option[/* max 100 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), email: /* max 254 chars */ String = random.alphanumeric.take(20).mkString, phone: /* max 8 chars */ String = random.alphanumeric.take(8).mkString, likesPizza: Boolean = random.nextBoolean(), workEmail: Option[/* max 254 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), id: Defaulted[PersonId] = Defaulted.UseDefault, maritalStatusId: Defaulted[MaritalStatusId] = Defaulted.UseDefault, sector: Defaulted[Sector] = Defaulted.UseDefault, favoriteNumber: Defaulted[Number] = Defaulted.UseDefault)(implicit c: Connection): testdb.hardcoded.myschema.person.PersonRow = testdb.hardcoded.myschema.person.PersonRepoImpl.insert(new testdb.hardcoded.myschema.person.PersonRowUnsaved(favouriteFootballClubId = favouriteFootballClubId, name = name, nickName = nickName, blogUrl = blogUrl, email = email, phone = phone, likesPizza = likesPizza, workEmail = workEmail, id = id, maritalStatusId = maritalStatusId, sector = sector, favoriteNumber = favoriteNumber))
def compositepkPerson(name: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), one: Defaulted[Long] = Defaulted.UseDefault, two: Defaulted[Option[String]] = Defaulted.UseDefault)(implicit c: Connection): PersonRow = (new PersonRepoImpl).insert(new PersonRowUnsaved(name = name, one = one, two = two))
def myschemaFootballClub(id: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString)(implicit c: Connection): FootballClubRow = (new FootballClubRepoImpl).insert(new FootballClubRow(id = id, name = name))
def myschemaMaritalStatus(id: MaritalStatusId)(implicit c: Connection): MaritalStatusRow = (new MaritalStatusRepoImpl).insert(new MaritalStatusRow(id = id))
def myschemaPerson(favouriteFootballClubId: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString, nickName: Option[/* max 30 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), blogUrl: Option[/* max 100 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), email: /* max 254 chars */ String = random.alphanumeric.take(20).mkString, phone: /* max 8 chars */ String = random.alphanumeric.take(8).mkString, likesPizza: Boolean = random.nextBoolean(), workEmail: Option[/* max 254 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), id: Defaulted[PersonId] = Defaulted.UseDefault, maritalStatusId: Defaulted[MaritalStatusId] = Defaulted.UseDefault, sector: Defaulted[Sector] = Defaulted.UseDefault, favoriteNumber: Defaulted[Number] = Defaulted.UseDefault)(implicit c: Connection): testdb.hardcoded.myschema.person.PersonRow = (new testdb.hardcoded.myschema.person.PersonRepoImpl).insert(new testdb.hardcoded.myschema.person.PersonRowUnsaved(favouriteFootballClubId = favouriteFootballClubId, name = name, nickName = nickName, blogUrl = blogUrl, email = email, phone = phone, likesPizza = likesPizza, workEmail = workEmail, id = id, maritalStatusId = maritalStatusId, sector = sector, favoriteNumber = favoriteNumber))
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object PersonRepoImpl extends PersonRepo {
class PersonRepoImpl extends PersonRepo {
override def delete(compositeId: PersonId)(implicit c: Connection): Boolean = {
SQL"""delete from compositepk.person where "one" = ${ParameterValue(compositeId.one, null, ToStatement.longToStatement)} AND "two" = ${ParameterValue(compositeId.two, null, ToStatement.optionToStatement(ToStatement.stringToStatement, ParameterMetaData.StringParameterMetaData))}""".executeUpdate() > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object FootballClubRepoImpl extends FootballClubRepo {
class FootballClubRepoImpl extends FootballClubRepo {
override def delete(id: FootballClubId)(implicit c: Connection): Boolean = {
SQL"""delete from myschema.football_club where "id" = ${ParameterValue(id, null, FootballClubId.toStatement)}""".executeUpdate() > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object MaritalStatusRepoImpl extends MaritalStatusRepo {
class MaritalStatusRepoImpl extends MaritalStatusRepo {
override def delete(id: MaritalStatusId)(implicit c: Connection): Boolean = {
SQL"""delete from myschema.marital_status where "id" = ${ParameterValue(id, null, MaritalStatusId.toStatement)}""".executeUpdate() > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object PersonRepoImpl extends PersonRepo {
class PersonRepoImpl extends PersonRepo {
override def delete(id: PersonId)(implicit c: Connection): Boolean = {
SQL"""delete from myschema.person where "id" = ${ParameterValue(id, null, PersonId.toStatement)}""".executeUpdate() > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import testdb.hardcoded.myschema.marital_status.MaritalStatusRow
import testdb.hardcoded.myschema.person.PersonId

class testInsert(random: Random) {
def compositepkPerson(name: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), one: Defaulted[Long] = Defaulted.UseDefault, two: Defaulted[Option[String]] = Defaulted.UseDefault)(implicit c: Connection): PersonRow = PersonRepoImpl.insert(new PersonRowUnsaved(name = name, one = one, two = two))
def myschemaFootballClub(id: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString)(implicit c: Connection): FootballClubRow = FootballClubRepoImpl.insert(new FootballClubRow(id = id, name = name))
def myschemaMaritalStatus(id: MaritalStatusId)(implicit c: Connection): MaritalStatusRow = MaritalStatusRepoImpl.insert(new MaritalStatusRow(id = id))
def myschemaPerson(favouriteFootballClubId: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString, nickName: Option[/* max 30 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), blogUrl: Option[/* max 100 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), email: /* max 254 chars */ String = random.alphanumeric.take(20).mkString, phone: /* max 8 chars */ String = random.alphanumeric.take(8).mkString, likesPizza: Boolean = random.nextBoolean(), workEmail: Option[/* max 254 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), id: Defaulted[PersonId] = Defaulted.UseDefault, maritalStatusId: Defaulted[MaritalStatusId] = Defaulted.UseDefault, sector: Defaulted[Sector] = Defaulted.UseDefault, favoriteNumber: Defaulted[Number] = Defaulted.UseDefault)(implicit c: Connection): testdb.hardcoded.myschema.person.PersonRow = testdb.hardcoded.myschema.person.PersonRepoImpl.insert(new testdb.hardcoded.myschema.person.PersonRowUnsaved(favouriteFootballClubId = favouriteFootballClubId, name = name, nickName = nickName, blogUrl = blogUrl, email = email, phone = phone, likesPizza = likesPizza, workEmail = workEmail, id = id, maritalStatusId = maritalStatusId, sector = sector, favoriteNumber = favoriteNumber))
def compositepkPerson(name: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), one: Defaulted[Long] = Defaulted.UseDefault, two: Defaulted[Option[String]] = Defaulted.UseDefault)(implicit c: Connection): PersonRow = (new PersonRepoImpl).insert(new PersonRowUnsaved(name = name, one = one, two = two))
def myschemaFootballClub(id: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString)(implicit c: Connection): FootballClubRow = (new FootballClubRepoImpl).insert(new FootballClubRow(id = id, name = name))
def myschemaMaritalStatus(id: MaritalStatusId)(implicit c: Connection): MaritalStatusRow = (new MaritalStatusRepoImpl).insert(new MaritalStatusRow(id = id))
def myschemaPerson(favouriteFootballClubId: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString, nickName: Option[/* max 30 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), blogUrl: Option[/* max 100 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), email: /* max 254 chars */ String = random.alphanumeric.take(20).mkString, phone: /* max 8 chars */ String = random.alphanumeric.take(8).mkString, likesPizza: Boolean = random.nextBoolean(), workEmail: Option[/* max 254 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), id: Defaulted[PersonId] = Defaulted.UseDefault, maritalStatusId: Defaulted[MaritalStatusId] = Defaulted.UseDefault, sector: Defaulted[Sector] = Defaulted.UseDefault, favoriteNumber: Defaulted[Number] = Defaulted.UseDefault)(implicit c: Connection): testdb.hardcoded.myschema.person.PersonRow = (new testdb.hardcoded.myschema.person.PersonRepoImpl).insert(new testdb.hardcoded.myschema.person.PersonRowUnsaved(favouriteFootballClubId = favouriteFootballClubId, name = name, nickName = nickName, blogUrl = blogUrl, email = email, phone = phone, likesPizza = likesPizza, workEmail = workEmail, id = id, maritalStatusId = maritalStatusId, sector = sector, favoriteNumber = favoriteNumber))
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object PersonRepoImpl extends PersonRepo {
class PersonRepoImpl extends PersonRepo {
override def delete(compositeId: PersonId)(implicit c: Connection): Boolean = {
SQL"""delete from compositepk.person where "one" = ${ParameterValue(compositeId.one, null, ToStatement.longToStatement)} AND "two" = ${ParameterValue(compositeId.two, null, ToStatement.optionToStatement(ToStatement.stringToStatement, ParameterMetaData.StringParameterMetaData))}""".executeUpdate() > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object FootballClubRepoImpl extends FootballClubRepo {
class FootballClubRepoImpl extends FootballClubRepo {
override def delete(id: FootballClubId)(implicit c: Connection): Boolean = {
SQL"""delete from myschema.football_club where "id" = ${ParameterValue(id, null, FootballClubId.toStatement)}""".executeUpdate() > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object MaritalStatusRepoImpl extends MaritalStatusRepo {
class MaritalStatusRepoImpl extends MaritalStatusRepo {
override def delete(id: MaritalStatusId)(implicit c: Connection): Boolean = {
SQL"""delete from myschema.marital_status where "id" = ${ParameterValue(id, null, MaritalStatusId.toStatement)}""".executeUpdate() > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object PersonRepoImpl extends PersonRepo {
class PersonRepoImpl extends PersonRepo {
override def delete(id: PersonId)(implicit c: Connection): Boolean = {
SQL"""delete from myschema.person where "id" = ${ParameterValue(id, null, PersonId.toStatement)}""".executeUpdate() > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import testdb.hardcoded.myschema.marital_status.MaritalStatusRow
import testdb.hardcoded.myschema.person.PersonId

class testInsert(random: Random) {
def compositepkPerson(name: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), one: Defaulted[Long] = Defaulted.UseDefault, two: Defaulted[Option[String]] = Defaulted.UseDefault)(implicit c: Connection): PersonRow = PersonRepoImpl.insert(new PersonRowUnsaved(name = name, one = one, two = two))
def myschemaFootballClub(id: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString)(implicit c: Connection): FootballClubRow = FootballClubRepoImpl.insert(new FootballClubRow(id = id, name = name))
def myschemaMaritalStatus(id: MaritalStatusId)(implicit c: Connection): MaritalStatusRow = MaritalStatusRepoImpl.insert(new MaritalStatusRow(id = id))
def myschemaPerson(favouriteFootballClubId: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString, nickName: Option[/* max 30 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), blogUrl: Option[/* max 100 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), email: /* max 254 chars */ String = random.alphanumeric.take(20).mkString, phone: /* max 8 chars */ String = random.alphanumeric.take(8).mkString, likesPizza: Boolean = random.nextBoolean(), workEmail: Option[/* max 254 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), id: Defaulted[PersonId] = Defaulted.UseDefault, maritalStatusId: Defaulted[MaritalStatusId] = Defaulted.UseDefault, sector: Defaulted[Sector] = Defaulted.UseDefault, favoriteNumber: Defaulted[Number] = Defaulted.UseDefault)(implicit c: Connection): testdb.hardcoded.myschema.person.PersonRow = testdb.hardcoded.myschema.person.PersonRepoImpl.insert(new testdb.hardcoded.myschema.person.PersonRowUnsaved(favouriteFootballClubId = favouriteFootballClubId, name = name, nickName = nickName, blogUrl = blogUrl, email = email, phone = phone, likesPizza = likesPizza, workEmail = workEmail, id = id, maritalStatusId = maritalStatusId, sector = sector, favoriteNumber = favoriteNumber))
def compositepkPerson(name: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), one: Defaulted[Long] = Defaulted.UseDefault, two: Defaulted[Option[String]] = Defaulted.UseDefault)(implicit c: Connection): PersonRow = (new PersonRepoImpl).insert(new PersonRowUnsaved(name = name, one = one, two = two))
def myschemaFootballClub(id: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString)(implicit c: Connection): FootballClubRow = (new FootballClubRepoImpl).insert(new FootballClubRow(id = id, name = name))
def myschemaMaritalStatus(id: MaritalStatusId)(implicit c: Connection): MaritalStatusRow = (new MaritalStatusRepoImpl).insert(new MaritalStatusRow(id = id))
def myschemaPerson(favouriteFootballClubId: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString, nickName: Option[/* max 30 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), blogUrl: Option[/* max 100 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), email: /* max 254 chars */ String = random.alphanumeric.take(20).mkString, phone: /* max 8 chars */ String = random.alphanumeric.take(8).mkString, likesPizza: Boolean = random.nextBoolean(), workEmail: Option[/* max 254 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), id: Defaulted[PersonId] = Defaulted.UseDefault, maritalStatusId: Defaulted[MaritalStatusId] = Defaulted.UseDefault, sector: Defaulted[Sector] = Defaulted.UseDefault, favoriteNumber: Defaulted[Number] = Defaulted.UseDefault)(implicit c: Connection): testdb.hardcoded.myschema.person.PersonRow = (new testdb.hardcoded.myschema.person.PersonRepoImpl).insert(new testdb.hardcoded.myschema.person.PersonRowUnsaved(favouriteFootballClubId = favouriteFootballClubId, name = name, nickName = nickName, blogUrl = blogUrl, email = email, phone = phone, likesPizza = likesPizza, workEmail = workEmail, id = id, maritalStatusId = maritalStatusId, sector = sector, favoriteNumber = favoriteNumber))
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object PersonRepoImpl extends PersonRepo {
class PersonRepoImpl extends PersonRepo {
override def delete(compositeId: PersonId): ConnectionIO[Boolean] = {
sql"""delete from compositepk.person where "one" = ${fromWrite(compositeId.one)(Write.fromPut(Meta.LongMeta.put))} AND "two" = ${fromWrite(compositeId.two)(Write.fromPutOption(Meta.StringMeta.put))}""".update.run.map(_ > 0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import typo.dsl.SelectBuilder
import typo.dsl.SelectBuilderSql
import typo.dsl.UpdateBuilder

object FootballClubRepoImpl extends FootballClubRepo {
class FootballClubRepoImpl extends FootballClubRepo {
override def delete(id: FootballClubId): ConnectionIO[Boolean] = {
sql"""delete from myschema.football_club where "id" = ${fromWrite(id)(Write.fromPut(FootballClubId.put))}""".update.run.map(_ > 0)
}
Expand Down
Loading

0 comments on commit 24ef0fc

Please sign in to comment.