Comments (6)
Thanks @nrf110, really appreciate the feedback. I've added a bit to the PR to support updating list elements, which surprised me by leading me to make things simpler.
from scanamo.
Interesting, thanks for raising this and sorry for breaking it.
Whilst I tend to try and avoid overloading, my preference would probably be towards just making it work for the existing methods.
from scanamo.
OK, this isn't quite as simple as I thought it might be due to the joys of http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ExpressionPlaceholders.html#ExpressionAttributeNames, but I've got a plan. I'm thinking you'd write something of the form:
outers.update('id -> id, set('inner \ 'field -> "value"))
Does that seem like a sensible approach? I think it would be nice to avoid encoding the separator within the string.
from scanamo.
Thanks for the quick response!
I definitely prefer your approach over encoding it in the string, and it covers our existing simple use cases. To make this handle all nested fields though, I think there is still the case of updating elements within a List, i.e. foo.bar[2] = baz
Extending your example a bit, how do you feel about something like this? (obviously we'd need to add a few more implicit conversions):
sealed trait PathNode {
def name: String
def separator: String
def placeholder: String
}
case class KeyPathNode(s: Symbol) extends PathNode{
def name: String = s.name
def separator = "."
def placeholder: String = s"#update${s.name}"
}
case class IndexPathNode(i: Int) extends PathNode {
def name: String = s"[$i]"
def separator: String = s""
def placeholder: String = name
}
case class Field(traversal: NonEmptyVector[PathNode]) {
val placeholder: String = traversal.foldLeft("")((l, r) => s"$l${r.separator}${r.placeholder}")
val name: String = traversal.tail.foldLeft(traversal.head.name)((l, r) => s"$l${r.separator}${r.name}")
val attributeNames: Map[String, String] = { // TODO: Not sure if/how we are supposed to map the list indices
traversal.filter {
case _: KeyPathNode => true
case _ => false
}.map(node => node.placeholder -> node.name).toMap
}
def \ (inner: Symbol): Field = Field(traversal.append(KeyPathNode(inner)))
def apply(idx: Int): Field = Field(traversal.append(IndexPathNode(idx)))
}
usage would then look like:
outers.update('id -> id, ('inner \ 'field)(2) -> "value")
from scanamo.
The implementation looks good, I like the simplification. 👍
from scanamo.
Closing this, as there's now an alternative available in 0.9.1
from scanamo.
Related Issues (20)
- Extend transactPutAll, transactUpdateAll and transactDeleteAll with optional ConditionExpression argument HOT 2
- Extend scan operation with Segments
- Adopt `sbt-dynamodb` into the Scanamo organisation? HOT 3
- Not able to use >= on string sort key
- Publish latest?
- Question: Should I be instantiating a different client per service?
- migrate to github action HOT 6
- Conditionally apply a filter
- [error] clienterror: an error occurred (validationexception) when calling the putitem operation: one or more parameter values were invalid: contains duplicates. HOT 1
- PutReturn.NewValue is not supported by AWS DynamoDB
- Scala 3 HOT 3
- Scanamo query timeouts...
- Null Pointer Exception when trying to call any methods accessing DynamoDb
- Where is the API documentation? HOT 1
- Pagination against GSIs is cumbersome with the current API.
- Add support for BigInt
- Pekko integration HOT 1
- ZIO 2 support
- Let's release v1.0.0 and drop milestone releases! HOT 3
- Error when case class has more than 36 properties
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scanamo.