Skip to main content
Version: 2.x

ProjectionExpression

The ProjectionExpression API is common to both the Type Safe High Level API (with the exception the primary keys API) and the Low Level API - however the way one is constructed is different.

High Level API construction

final case class Person(id: String, group: String name: String)
object Person {
implicit val schema: Schema.CaseClass3[String, String, String, Person] = DeriveSchema.gen[Person]

// id and name are ProjectionExpressions
val (id, group, name) = ProjectionExpression.accessors[Person]
}

Low Level API construction

// id and name are ProjectionExpressions
val id = ProjectionExpression.$("id")
val name = ProjectionExpression.$("name")

For more details see $ and Parse functions section

Type Safety

The other notable difference is that High Level API is totally type safe and many subtle errors are caught at compile time:

Person.id === 1 // will not compile
Person.id === "1" && Person.name === 2 // will not compile
Person.id === "1" && Employee.name === "2" // will not compile

ProjectionExpression.$("name") === 1 // will compile!

ProjectionExpression API Summary​

Once we have a ProjectionExpression we can use it as a springboard to create further expressions such as ConditionExpression, UpdateExpression and PrimaryKeyExpression:

CategoryMethodDescription
Primary Keys (High Level API only)partitionKeyPerson.id.partitionKey === "1"


sortKeyPerson.id.partitionKey === "1" && Person.group.sortKey === "2"
ConditionExpression / FilterExpression===Equality


<>Inequality


>Greater than


>=Greater than or equal


<Less than


<=Less than or equal


existsreturns true if the attribute exists


notExistsreturns true if the attribute does not exists


sizereturns size of attribute. Applies to all types except Number and Boolean


isXXXXThere is a function per type eg isBinary - returns true if the attribute is of the specified type


between(from, to)returns true if the attribute is between the supplied values, inclusive


beginsWithOnly applies to string attributes


inSetreturns true if the attribute is in the supplied set


in(a, b, c ...)returns true if the attribute matches one of the supplied values


containsreturns true if the attribute contains the supplied value - applies to a String or a Set
UpdateExpression+combines update actions eg Person.name.set(42) + Person.age.set(42)


setSet an attribute Person.name.set("John")


setIfNotExistsSet attribute if it does not exists Person.name.setIfNotExists("John")


appendListAdd supplied list to the end of this list attribute


prependPrepend an element to a list attribute


prependListPrepend a list to list attribute


deleteFromSetdelete all elements that match the supplied set


add(a: To)adds this value as a number attribute if it does not exists, else adds the numeric value to the existing attribute


addSetAdds this set as an attribute if it does not exists, else if it exists it adds the elements of the set


remove(index: Int)remove an element at the specified index


removeRemoves this path expression from an item