Make CRUDAction types more strict (#4657)

This commit is contained in:
benthecarman 2022-08-24 06:15:24 -05:00 committed by GitHub
parent 7c112b8a90
commit 02f525fd39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 34 additions and 25 deletions

View File

@ -48,14 +48,14 @@ case class ChainStateDescriptorDAO()(implicit
} }
override def findByPrimaryKey(id: ChainStateDescriptorType): Query[ override def findByPrimaryKey(id: ChainStateDescriptorType): Query[
Table[_], Table[ChainStateDescriptorDb],
ChainStateDescriptorDb, ChainStateDescriptorDb,
Seq] = { Seq] = {
table.filter(_.tpe === id) table.filter(_.tpe === id)
} }
override def findAll(ts: Vector[ChainStateDescriptorDb]): Query[ override def findAll(ts: Vector[ChainStateDescriptorDb]): Query[
Table[_], Table[ChainStateDescriptorDb],
ChainStateDescriptorDb, ChainStateDescriptorDb,
Seq] = Seq] =
findByPrimaryKeys(ts.map(_.tpe)) findByPrimaryKeys(ts.map(_.tpe))

View File

@ -75,8 +75,10 @@ case class CompactFilterDAO()(implicit
table.filter(_.blockHash.inSet(ids)) table.filter(_.blockHash.inSet(ids))
} }
override protected def findAll( override protected def findAll(ts: Vector[CompactFilterDb]): Query[
ts: Vector[CompactFilterDb]): Query[Table[_], CompactFilterDb, Seq] = { Table[CompactFilterDb],
CompactFilterDb,
Seq] = {
findByPrimaryKeys(ts.map(_.blockHashBE)) findByPrimaryKeys(ts.map(_.blockHashBE))
} }

View File

@ -71,7 +71,7 @@ case class CompactFilterHeaderDAO()(implicit
table.filter(_.hash.inSet(ids)) table.filter(_.hash.inSet(ids))
override protected def findAll(ts: Vector[CompactFilterHeaderDb]): Query[ override protected def findAll(ts: Vector[CompactFilterHeaderDb]): Query[
Table[_], Table[CompactFilterHeaderDb],
CompactFilterHeaderDb, CompactFilterHeaderDb,
Seq] = Seq] =
findByPrimaryKeys(ts.map(_.hashBE)) findByPrimaryKeys(ts.map(_.hashBE))

View File

@ -30,10 +30,10 @@ abstract class CRUDAction[T, PrimaryKeyType](implicit
/** return all rows that have a certain primary key /** return all rows that have a certain primary key
* *
* @param id * @param id primary key of the row to return
* @return Query object corresponding to the selected rows * @return Query object corresponding to the selected rows
*/ */
protected def findByPrimaryKey(id: PrimaryKeyType): Query[Table[_], T, Seq] = protected def findByPrimaryKey(id: PrimaryKeyType): Query[Table[T], T, Seq] =
findByPrimaryKeys(Vector(id)) findByPrimaryKeys(Vector(id))
/** Finds the rows that correlate to the given primary keys */ /** Finds the rows that correlate to the given primary keys */
@ -58,9 +58,9 @@ abstract class CRUDAction[T, PrimaryKeyType](implicit
.map(_.headOption) .map(_.headOption)
} }
protected def find(t: T): Query[Table[_], T, Seq] = findAll(Vector(t)) protected def find(t: T): Query[Table[T], T, Seq] = findAll(Vector(t))
protected def findAll(ts: Vector[T]): Query[Table[_], T, Seq] protected def findAll(ts: Vector[T]): Query[Table[T], T, Seq]
def findAllAction(): DBIOAction[ def findAllAction(): DBIOAction[
Vector[T], Vector[T],

View File

@ -32,6 +32,10 @@ abstract class CRUDAutoInc[T <: DbRowAutoInc[T]](implicit
safeDatabase.runVec(actions) safeDatabase.runVec(actions)
} }
override protected def findByPrimaryKey(
id: Long): Query[TableAutoInc[T], T, Seq] =
table.filter(_.id === id)
override def findByPrimaryKeys( override def findByPrimaryKeys(
ids: Vector[Long]): Query[TableAutoInc[T], T, Seq] = { ids: Vector[Long]): Query[TableAutoInc[T], T, Seq] = {
table.filter { t => table.filter { t =>
@ -39,7 +43,7 @@ abstract class CRUDAutoInc[T <: DbRowAutoInc[T]](implicit
} }
} }
override def findAll(ts: Vector[T]): Query[Table[_], T, Seq] = { override def findAll(ts: Vector[T]): Query[Table[T], T, Seq] = {
val ids = ts.filter(_.id.isDefined).map(_.id.get) val ids = ts.filter(_.id.isDefined).map(_.id.get)
findByPrimaryKeys(ids) findByPrimaryKeys(ids)
} }

View File

@ -87,7 +87,7 @@ case class MasterXPubDAO()(implicit
override protected def findAll( override protected def findAll(
ts: Vector[ExtPublicKeyDTO]): profile.api.Query[ ts: Vector[ExtPublicKeyDTO]): profile.api.Query[
profile.api.Table[_], profile.api.Table[ExtPublicKeyDTO],
ExtPublicKeyDTO, ExtPublicKeyDTO,
Seq] = { Seq] = {
findByPrimaryKeys(ts.map(_.publicKey)) findByPrimaryKeys(ts.map(_.publicKey))

View File

@ -63,7 +63,7 @@ case class DLCAnnouncementDAO()(implicit
} }
override def find(t: DLCAnnouncementDb): profile.api.Query[ override def find(t: DLCAnnouncementDb): profile.api.Query[
Table[_], Table[DLCAnnouncementDb],
DLCAnnouncementDb, DLCAnnouncementDb,
Seq] = { Seq] = {
findByPrimaryKey(DLCAnnouncementPrimaryKey(t.dlcId, t.announcementId)) findByPrimaryKey(DLCAnnouncementPrimaryKey(t.dlcId, t.announcementId))

View File

@ -38,7 +38,7 @@ case class IncomingDLCOfferDAO()(implicit
table.filter(_.hash.inSet(ids)) table.filter(_.hash.inSet(ids))
override protected def findAll(ts: Vector[IncomingDLCOfferDb]): Query[ override protected def findAll(ts: Vector[IncomingDLCOfferDb]): Query[
Table[_], Table[IncomingDLCOfferDb],
IncomingDLCOfferDb, IncomingDLCOfferDb,
Seq] = Seq] =
findByPrimaryKeys(ts.map(_.hash)) findByPrimaryKeys(ts.map(_.hash))

View File

@ -49,19 +49,22 @@ case class OracleNonceDAO()(implicit
override protected def findByPrimaryKey( override protected def findByPrimaryKey(
id: OracleNoncePrimaryKey): profile.api.Query[ id: OracleNoncePrimaryKey): profile.api.Query[
profile.api.Table[_], profile.api.Table[OracleNonceDb],
OracleNonceDb, OracleNonceDb,
Seq] = { Seq] = {
table.filter(t => table.filter(t =>
t.announcementId === id.announcementId && t.index === id.index) t.announcementId === id.announcementId && t.index === id.index)
} }
override def find(t: OracleNonceDb): Query[Table[_], OracleNonceDb, Seq] = { override def find(
t: OracleNonceDb): Query[Table[OracleNonceDb], OracleNonceDb, Seq] = {
findByPrimaryKey(OracleNoncePrimaryKey(t.announcementId, t.index)) findByPrimaryKey(OracleNoncePrimaryKey(t.announcementId, t.index))
} }
override protected def findAll( override protected def findAll(ts: Vector[OracleNonceDb]): Query[
ts: Vector[OracleNonceDb]): Query[Table[_], OracleNonceDb, Seq] = Table[OracleNonceDb],
OracleNonceDb,
Seq] =
findByPrimaryKeys( findByPrimaryKeys(
ts.map(t => OracleNoncePrimaryKey(t.announcementId, t.index))) ts.map(t => OracleNoncePrimaryKey(t.announcementId, t.index)))

View File

@ -42,14 +42,14 @@ case class NodeStateDescriptorDAO()(implicit
} }
override def findByPrimaryKey(id: NodeStateDescriptorType): Query[ override def findByPrimaryKey(id: NodeStateDescriptorType): Query[
Table[_], Table[NodeStateDescriptorDb],
NodeStateDescriptorDb, NodeStateDescriptorDb,
Seq] = { Seq] = {
table.filter(_.tpe === id) table.filter(_.tpe === id)
} }
override def findAll(ts: Vector[NodeStateDescriptorDb]): Query[ override def findAll(ts: Vector[NodeStateDescriptorDb]): Query[
Table[_], Table[NodeStateDescriptorDb],
NodeStateDescriptorDb, NodeStateDescriptorDb,
Seq] = Seq] =
findByPrimaryKeys(ts.map(_.tpe)) findByPrimaryKeys(ts.map(_.tpe))

View File

@ -38,8 +38,8 @@ case class PeerDAO()(implicit ec: ExecutionContext, appConfig: NodeAppConfig)
} }
override protected def findAll( override protected def findAll(
ts: Vector[PeerDb]): Query[Table[_], PeerDb, Seq] = findByPrimaryKeys( ts: Vector[PeerDb]): Query[Table[PeerDb], PeerDb, Seq] =
ts.map(_.address)) findByPrimaryKeys(ts.map(_.address))
def deleteByKey(address: String): Future[Int] = { def deleteByKey(address: String): Future[Int] = {
val bytes = ByteVector(address.getBytes) val bytes = ByteVector(address.getBytes)

View File

@ -60,7 +60,7 @@ case class AddressTagDAO()(implicit
} }
override def findByPrimaryKey(id: (BitcoinAddress, AddressTagType)): Query[ override def findByPrimaryKey(id: (BitcoinAddress, AddressTagType)): Query[
Table[_], Table[AddressTagDb],
AddressTagDb, AddressTagDb,
Seq] = { Seq] = {
val (address, tagType) = id val (address, tagType) = id
@ -70,7 +70,7 @@ case class AddressTagDAO()(implicit
} }
override def findAll( override def findAll(
ts: Vector[AddressTagDb]): Query[Table[_], AddressTagDb, Seq] = ts: Vector[AddressTagDb]): Query[Table[AddressTagDb], AddressTagDb, Seq] =
findByPrimaryKeys(ts.map(t => (t.address, t.tagType))) findByPrimaryKeys(ts.map(t => (t.address, t.tagType)))
def findByAddressAction(address: BitcoinAddress): DBIOAction[ def findByAddressAction(address: BitcoinAddress): DBIOAction[

View File

@ -47,14 +47,14 @@ case class WalletStateDescriptorDAO()(implicit
} }
override def findByPrimaryKey(id: WalletStateDescriptorType): Query[ override def findByPrimaryKey(id: WalletStateDescriptorType): Query[
Table[_], Table[WalletStateDescriptorDb],
WalletStateDescriptorDb, WalletStateDescriptorDb,
Seq] = { Seq] = {
table.filter(_.tpe === id) table.filter(_.tpe === id)
} }
override def findAll(ts: Vector[WalletStateDescriptorDb]): Query[ override def findAll(ts: Vector[WalletStateDescriptorDb]): Query[
Table[_], Table[WalletStateDescriptorDb],
WalletStateDescriptorDb, WalletStateDescriptorDb,
Seq] = Seq] =
findByPrimaryKeys(ts.map(_.tpe)) findByPrimaryKeys(ts.map(_.tpe))