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[
Table[_],
Table[ChainStateDescriptorDb],
ChainStateDescriptorDb,
Seq] = {
table.filter(_.tpe === id)
}
override def findAll(ts: Vector[ChainStateDescriptorDb]): Query[
Table[_],
Table[ChainStateDescriptorDb],
ChainStateDescriptorDb,
Seq] =
findByPrimaryKeys(ts.map(_.tpe))

View File

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

View File

@ -71,7 +71,7 @@ case class CompactFilterHeaderDAO()(implicit
table.filter(_.hash.inSet(ids))
override protected def findAll(ts: Vector[CompactFilterHeaderDb]): Query[
Table[_],
Table[CompactFilterHeaderDb],
CompactFilterHeaderDb,
Seq] =
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
*
* @param id
* @param id primary key of the row to return
* @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))
/** Finds the rows that correlate to the given primary keys */
@ -58,9 +58,9 @@ abstract class CRUDAction[T, PrimaryKeyType](implicit
.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[
Vector[T],

View File

@ -32,6 +32,10 @@ abstract class CRUDAutoInc[T <: DbRowAutoInc[T]](implicit
safeDatabase.runVec(actions)
}
override protected def findByPrimaryKey(
id: Long): Query[TableAutoInc[T], T, Seq] =
table.filter(_.id === id)
override def findByPrimaryKeys(
ids: Vector[Long]): Query[TableAutoInc[T], T, Seq] = {
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)
findByPrimaryKeys(ids)
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -60,7 +60,7 @@ case class AddressTagDAO()(implicit
}
override def findByPrimaryKey(id: (BitcoinAddress, AddressTagType)): Query[
Table[_],
Table[AddressTagDb],
AddressTagDb,
Seq] = {
val (address, tagType) = id
@ -70,7 +70,7 @@ case class AddressTagDAO()(implicit
}
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)))
def findByAddressAction(address: BitcoinAddress): DBIOAction[

View File

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