postgresql - Slick 2.0 Generic CRUD operations -


I see how to implement a common feature for common CRUDs and other types of operations, I saw and And the specified method is working well.

What do I want is a common method for the inclusion, at this time my class looks like this (non-normal implementation):

  object campaign mode {val campaign = Tables [Campaign] def insert (Campaign: CampaignRow) (built-in: session) = {campaigns.insert (campaign)}}  

I tried to do this first, after the following link, This (General Implementation) was:

  Post Graduate Generic [T & lt;: Table [A], A] {Val Tablerefer S = tables [t] DRF darz generic (line:  

When I inspect the insert method it looks like the correct type should be T # TableElementType But my knowledge is PR ATT origin and I can not wrap my head around, I tried T and A and the compiler says That is not the case with the ClassStep property.

  Case class campaign (id: long, name: option [ String]) / ** table description of table campaign. The objects of this class work as prototypes for rows in questions. * / Class campaign (tag: tag) table [campaign line] (tag, "campaign") {def * = (id, name) & lt; & Gt; (CampaignRow.tupled, CampaignRow.unapply) / ** Enhances an entire line of maps. Useful for external joining * / def? = (Id., Name). Shaped & Lt; & Gt; ({R = & gt; Import R._; _1.map (_ = & amp; CampaignRow.tupled ((_ 1.get, _2))}), (_: any) => New Exception ("Not included in launch.")) / ** Database column id AutoInc, PrimaryKey * / val id: column [long] = column [tall] ("id" O.AutoInc, O.PrimaryKey) / ** Database column name * / Val name: column [option [string]] = column [option [string]] ("name")}  

I managed to work it out, this is my usual symptom:

  import scala.slick.driver.PostgresDriver import scala.slick.driver.PostgresDriver.simple._ Import path.to.RichTable attribute PostgresGeneric [T & lt;: RichTable [A], A] {val Talikeference: Insert Tables [T] DRF (Row: T # TableElement Type) (Built-in: Session) = FilterReference.Instert (Row) Enter the DRFAndGet ID (Line: T # TableElement Type) (Built-in S: Session) = (Returning to Tablereering Table) ( ID: Long) (built-in: session): boolean = tablereferencefilter (_. Id === id) .delete == 1 def updated BIID (id: id) long, line: T # table element type) (built-in: session): boolean = tablereferencefiler (_. Id === id) .Update (line) == 1 Choosing DEFIID (ID: Long) (built-in: session): option [T # TableElementType] = tableReference.filter (_. Id === ID) .firstOption def is present BYId (ID: Long) (Built S: Session): Boolean = {({line for line {l = - table ID === ID} yield line) .firstOption.isDefined}}  

Where Pictorial is an abstract class with an ID class, it is useful to obtain the upper bound area code ID of T # tableElementType (see for more information):

  Import slila. Slick.driver.PostgresDriver.simple._ Import Slaal .slick.jdbc. {GetResult = & gt; Gr} intangible square richabile [t] (tag: tag, name: string) extends the table [t] (tag, name) {val id: column [long] = column [long] ("id", o primary , O.utoInc)}  

And my campaign table now looks like this:

  import scala.link.devor.postgrace driver.soledy._ import Scala.slick .jdbc {GetResult = & gt; GR} Import Scala.slick.lifted.TableQuery Case Category CampaignRow (id: long, name: option [string]) class campaign (tag: tag) extends RichTable [CampaignRow] (tag, "campaign") {def * = (Id, name) & lt; & Gt; (CampaignRow.tupled, CampaignRow.unapply) def? = .shaped & lt (id, name.?) ;. & Gt; ({R = & gt; import r._; _1.map (_ = & gt; CampaignRow.tupled ((_ 1.Get, _2))}, (_: any) = & gt; throw new exception ("Do not include launch in projection")) Override Val ID: Columns [Long] = Columns [Long] ("ID", O.AutoInc, O.PrimaryKey) Val Name: column [option [string]] = Model [string]] ("name")}  

A model that implements a generic feature looks like this:

  Object CampaignModel extends PostgresGeneric [ Campaign, CampaignRow] {Override Valid tableReference: PostgresDriver.simple.TableQuery [Tables.Campaign] = TableQuery [Campaign ] Def insertCampaign (line: CampaignRow) = {insert (CampaignRow (0, "test"))}}  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -