scala - Updating data in SORM seems possible (even though I was told it aimed at immutable data...) -
i told sorm aims @ immutable data. it's not written on website - @ least not in main parts looking at, bit surprized of rigidity of claim. aware recommend so. maybe missing something.
the examples tell use ".copy(propery = newvalue)" before calling db.save() on object. thats hint.
i interrested in happen if change data , update in database. strangely following worked fine:
case class agent( var name : string ) object db extends instance( entities = set( entity[agent]() ), url = "jdbc:h2:mem:hansi" ) class sormtest extends funsuite { test("update") { // store values in db: val agent = db.save( agent("test") ) agent.name = "hansi" db.save(agent) }
it produced update statement in database changed name property corresponding id.
is kind of crazy so? comments developers?
i told sorm aims @ immutable data. it's not written on website
it's stated plenty of times sorm follows functional programming idioms. implies operation on immutable data-structures only.
the examples tell use ".copy(propery = newvalue)" before calling db.save() on object.
that's you're wrong. examples tell use .copy(..)
updated immutable value of object it's called on, calling before calling db.save()
per se in following:
agent.copy(name = "new name") db.save(agent)
will have absolutely no effect, because, once again, .copy()
doesn't mutate object it's called on, instead returns updated copy of object. proper use following:
val updatedagent = agent.copy(name = "new name") db.save(updatedagent)
or simply:
db.save( agent.copy(name = "new name") )
but fact above has sorm as has functional programming in scala in general. basic stuff how case classes supposed used. please favor , introduce basics of functional programming. wipe out questions on sorm you've had and, i'm sure, plenty of comming otherwise.
your example works , it's supposed to, doesn't change fact goes against basic idioms of functional programming , such unidiomatic use of sorm.
Comments
Post a Comment