scala的orm框架,相比其他orm更为简洁
//Declareamodel:caseclassArtist(name:String,genres:Set[Genre])caseclassGenre(name:String)//InitializeSORM,automaticallygeneratingschema:importsorm._objectDbextendsInstance(entities=Set(Entity[Artist](),Entity[Genre]()),url="jdbc:h2:mem:test")//Storevaluesinthedb:valmetal=Db.save(Genre("Metal"))valrock=Db.save(Genre("Rock"))Db.save(Artist("Metallica",Set(metal,rock)))Db.save(Artist("DireStraits",Set(rock)))//Retrievevaluesfromthedb://Option[ArtistwithPersisted]:valmetallica=Db.query[Artist].whereEqual("name","Metallica").fetchOne()//Stream[ArtistwithPersisted]:valrockArtists=Db.query[Artist].whereEqual("genres.item.name","Rock").fetch()点击空白处退出提示
评论