| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577 |
- package expression
- import (
- "fmt"
- "strings"
- )
- // conditionMode specifies the types of the struct conditionBuilder,
- // representing the different types of Conditions (i.e. And, Or, Between, ...)
- type conditionMode int
- const (
- // unsetCond catches errors for unset ConditionBuilder structs
- unsetCond conditionMode = iota
- // equalCond represents the Equals Condition
- equalCond
- // notEqualCond represents the Not Equals Condition
- notEqualCond
- // lessThanCond represents the LessThan Condition
- lessThanCond
- // lessThanEqualCond represents the LessThanOrEqual Condition
- lessThanEqualCond
- // greaterThanCond represents the GreaterThan Condition
- greaterThanCond
- // greaterThanEqualCond represents the GreaterThanEqual Condition
- greaterThanEqualCond
- // andCond represents the Logical And Condition
- andCond
- // orCond represents the Logical Or Condition
- orCond
- // notCond represents the Logical Not Condition
- notCond
- // betweenCond represents the Between Condition
- betweenCond
- // inCond represents the In Condition
- inCond
- // attrExistsCond represents the Attribute Exists Condition
- attrExistsCond
- // attrNotExistsCond represents the Attribute Not Exists Condition
- attrNotExistsCond
- // attrTypeCond represents the Attribute Type Condition
- attrTypeCond
- // beginsWithCond represents the Begins With Condition
- beginsWithCond
- // containsCond represents the Contains Condition
- containsCond
- )
- // DynamoDBAttributeType specifies the type of an DynamoDB item attribute. This
- // enum is used in the AttributeType() function in order to be explicit about
- // the DynamoDB type that is being checked and ensure compile time checks.
- // More Informatin at http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions
- type DynamoDBAttributeType string
- const (
- // String represents the DynamoDB String type
- String DynamoDBAttributeType = "S"
- // StringSet represents the DynamoDB String Set type
- StringSet = "SS"
- // Number represents the DynamoDB Number type
- Number = "N"
- // NumberSet represents the DynamoDB Number Set type
- NumberSet = "NS"
- // Binary represents the DynamoDB Binary type
- Binary = "B"
- // BinarySet represents the DynamoDB Binary Set type
- BinarySet = "BS"
- // Boolean represents the DynamoDB Boolean type
- Boolean = "BOOL"
- // Null represents the DynamoDB Null type
- Null = "NULL"
- // List represents the DynamoDB List type
- List = "L"
- // Map represents the DynamoDB Map type
- Map = "M"
- )
- // ConditionBuilder represents Condition Expressions and Filter Expressions
- // in DynamoDB. ConditionBuilders are one of the building blocks of the Builder
- // struct. Since Filter Expressions support all the same functions and formats
- // as Condition Expressions, ConditionBuilders represents both types of
- // Expressions.
- // More Information at: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ConditionExpressions.html
- // More Information on Filter Expressions: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.FilterExpression
- type ConditionBuilder struct {
- operandList []OperandBuilder
- conditionList []ConditionBuilder
- mode conditionMode
- }
- // Equal returns a ConditionBuilder representing the equality clause of the two
- // argument OperandBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the equal clause of the item attribute "foo" and
- // // the value 5
- // condition := expression.Equal(expression.Name("foo"), expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Equal(expression.Name("foo"), expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "foo = :five"
- func Equal(left, right OperandBuilder) ConditionBuilder {
- return ConditionBuilder{
- operandList: []OperandBuilder{left, right},
- mode: equalCond,
- }
- }
- // Equal returns a ConditionBuilder representing the equality clause of the two
- // argument OperandBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the equal clause of the item attribute "foo" and
- // // the value 5
- // condition := expression.Name("foo").Equal(expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("foo").Equal(expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "foo = :five"
- func (nb NameBuilder) Equal(right OperandBuilder) ConditionBuilder {
- return Equal(nb, right)
- }
- // Equal returns a ConditionBuilder representing the equality clause of the two
- // argument OperandBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the equal clause of the item attribute "foo" and
- // // the value 5
- // condition := expression.Value(5).Equal(expression.Name("foo"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Value(5).Equal(expression.Name("foo"))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // ":five = foo"
- func (vb ValueBuilder) Equal(right OperandBuilder) ConditionBuilder {
- return Equal(vb, right)
- }
- // Equal returns a ConditionBuilder representing the equality clause of the two
- // argument OperandBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the equal clause of the size of the item
- // // attribute "foo" and the value 5
- // condition := expression.Size(expression.Name("foo")).Equal(expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Size(expression.Name("foo")).Equal(expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "size (foo) = :five"
- func (sb SizeBuilder) Equal(right OperandBuilder) ConditionBuilder {
- return Equal(sb, right)
- }
- // NotEqual returns a ConditionBuilder representing the not equal clause of the
- // two argument OperandBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the not equal clause of the item attribute "foo"
- // // and the value 5
- // condition := expression.NotEqual(expression.Name("foo"), expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.NotEqual(expression.Name("foo"), expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "foo <> :five"
- func NotEqual(left, right OperandBuilder) ConditionBuilder {
- return ConditionBuilder{
- operandList: []OperandBuilder{left, right},
- mode: notEqualCond,
- }
- }
- // NotEqual returns a ConditionBuilder representing the not equal clause of the
- // two argument OperandBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the not equal clause of the item attribute "foo"
- // // and the value 5
- // condition := expression.Name("foo").NotEqual(expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("foo").NotEqual(expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "foo <> :five"
- func (nb NameBuilder) NotEqual(right OperandBuilder) ConditionBuilder {
- return NotEqual(nb, right)
- }
- // NotEqual returns a ConditionBuilder representing the not equal clause of the
- // two argument OperandBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the not equal clause of the item attribute "foo"
- // // and the value 5
- // condition := expression.Value(5).NotEqual(expression.Name("foo"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Value(5).NotEqual(expression.Name("foo"))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // ":five <> foo"
- func (vb ValueBuilder) NotEqual(right OperandBuilder) ConditionBuilder {
- return NotEqual(vb, right)
- }
- // NotEqual returns a ConditionBuilder representing the not equal clause of the
- // two argument OperandBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the not equal clause of the size of the item
- // // attribute "foo" and the value 5
- // condition := expression.Size(expression.Name("foo")).NotEqual(expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Size(expression.Name("foo")).NotEqual(expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "size (foo) <> :five"
- func (sb SizeBuilder) NotEqual(right OperandBuilder) ConditionBuilder {
- return NotEqual(sb, right)
- }
- // LessThan returns a ConditionBuilder representing the less than clause of the
- // two argument OperandBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the less than clause of the item attribute "foo"
- // // and the value 5
- // condition := expression.LessThan(expression.Name("foo"), expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.LessThan(expression.Name("foo"), expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "foo < :five"
- func LessThan(left, right OperandBuilder) ConditionBuilder {
- return ConditionBuilder{
- operandList: []OperandBuilder{left, right},
- mode: lessThanCond,
- }
- }
- // LessThan returns a ConditionBuilder representing the less than clause of the
- // two argument OperandBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the less than clause of the item attribute "foo"
- // // and the value 5
- // condition := expression.Name("foo").LessThan(expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("foo").LessThan(expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "foo < :five"
- func (nb NameBuilder) LessThan(right OperandBuilder) ConditionBuilder {
- return LessThan(nb, right)
- }
- // LessThan returns a ConditionBuilder representing the less than clause of the
- // two argument OperandBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the less than clause of the item attribute "foo"
- // // and the value 5
- // condition := expression.Value(5).LessThan(expression.Name("foo"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Value(5).LessThan(expression.Name("foo"))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // ":five < foo"
- func (vb ValueBuilder) LessThan(right OperandBuilder) ConditionBuilder {
- return LessThan(vb, right)
- }
- // LessThan returns a ConditionBuilder representing the less than clause of the
- // two argument OperandBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the less than clause of the size of the item
- // // attribute "foo" and the value 5
- // condition := expression.Size(expression.Name("foo")).LessThan(expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Size(expression.Name("foo")).LessThan(expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "size (foo) < :five"
- func (sb SizeBuilder) LessThan(right OperandBuilder) ConditionBuilder {
- return LessThan(sb, right)
- }
- // LessThanEqual returns a ConditionBuilder representing the less than equal to
- // clause of the two argument OperandBuilders. The resulting ConditionBuilder
- // can be used as a part of other Condition Expressions or as an argument to the
- // WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the less than equal to clause of the item
- // // attribute "foo" and the value 5
- // condition := expression.LessThanEqual(expression.Name("foo"), expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.LessThanEqual(expression.Name("foo"), expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "foo <= :five"
- func LessThanEqual(left, right OperandBuilder) ConditionBuilder {
- return ConditionBuilder{
- operandList: []OperandBuilder{left, right},
- mode: lessThanEqualCond,
- }
- }
- // LessThanEqual returns a ConditionBuilder representing the less than equal to
- // clause of the two argument OperandBuilders. The resulting ConditionBuilder
- // can be used as a part of other Condition Expressions or as an argument to the
- // WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the less than equal to clause of the item
- // // attribute "foo" and the value 5
- // condition := expression.Name("foo").LessThanEqual(expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("foo").LessThanEqual(expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "foo <= :five"
- func (nb NameBuilder) LessThanEqual(right OperandBuilder) ConditionBuilder {
- return LessThanEqual(nb, right)
- }
- // LessThanEqual returns a ConditionBuilder representing the less than equal to
- // clause of the two argument OperandBuilders. The resulting ConditionBuilder
- // can be used as a part of other Condition Expressions or as an argument to the
- // WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the less than equal to clause of the item
- // // attribute "foo" and the value 5
- // condition := expression.Value(5).LessThanEqual(expression.Name("foo"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Value(5).LessThanEqual(expression.Name("foo"))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // ":five <= foo"
- func (vb ValueBuilder) LessThanEqual(right OperandBuilder) ConditionBuilder {
- return LessThanEqual(vb, right)
- }
- // LessThanEqual returns a ConditionBuilder representing the less than equal to
- // clause of the two argument OperandBuilders. The resulting ConditionBuilder
- // can be used as a part of other Condition Expressions or as an argument to the
- // WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the less than equal to clause of the size of the
- // // item attribute "foo" and the value 5
- // condition := expression.Size(expression.Name("foo")).LessThanEqual(expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Size(expression.Name("foo")).LessThanEqual(expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "size (foo) <= :five"
- func (sb SizeBuilder) LessThanEqual(right OperandBuilder) ConditionBuilder {
- return LessThanEqual(sb, right)
- }
- // GreaterThan returns a ConditionBuilder representing the greater than clause
- // of the two argument OperandBuilders. The resulting ConditionBuilder can be
- // used as a part of other Condition Expressions or as an argument to the
- // WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the greater than clause of the item attribute
- // // "foo" and the value 5
- // condition := expression.GreaterThan(expression.Name("foo"), expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.GreaterThan(expression.Name("foo"), expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "foo > :five"
- func GreaterThan(left, right OperandBuilder) ConditionBuilder {
- return ConditionBuilder{
- operandList: []OperandBuilder{left, right},
- mode: greaterThanCond,
- }
- }
- // GreaterThan returns a ConditionBuilder representing the greater than clause
- // of the two argument OperandBuilders. The resulting ConditionBuilder can be
- // used as a part of other Condition Expressions or as an argument to the
- // WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the greater than clause of the item attribute
- // // "foo" and the value 5
- // condition := expression.Name("foo").GreaterThan(expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("foo").GreaterThan(expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "foo > :five"
- func (nb NameBuilder) GreaterThan(right OperandBuilder) ConditionBuilder {
- return GreaterThan(nb, right)
- }
- // GreaterThan returns a ConditionBuilder representing the greater than clause
- // of the two argument OperandBuilders. The resulting ConditionBuilder can be
- // used as a part of other Condition Expressions or as an argument to the
- // WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the greater than clause of the item attribute
- // // "foo" and the value 5
- // condition := expression.Value(5).GreaterThan(expression.Name("foo"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Value(5).GreaterThan(expression.Name("foo"))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // ":five > foo"
- func (vb ValueBuilder) GreaterThan(right OperandBuilder) ConditionBuilder {
- return GreaterThan(vb, right)
- }
- // GreaterThan returns a ConditionBuilder representing the greater than
- // clause of the two argument OperandBuilders. The resulting ConditionBuilder
- // can be used as a part of other Condition Expressions or as an argument to the
- // WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the greater than clause of the size of the item
- // // attribute "foo" and the value 5
- // condition := expression.Size(expression.Name("foo")).GreaterThan(expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Size(expression.Name("foo")).GreaterThan(expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "size (foo) > :five"
- func (sb SizeBuilder) GreaterThan(right OperandBuilder) ConditionBuilder {
- return GreaterThan(sb, right)
- }
- // GreaterThanEqual returns a ConditionBuilder representing the greater than
- // equal to clause of the two argument OperandBuilders. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the greater than equal to clause of the item
- // // attribute "foo" and the value 5
- // condition := expression.GreaterThanEqual(expression.Name("foo"), expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.GreaterThanEqual(expression.Name("foo"), expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "foo >= :five"
- func GreaterThanEqual(left, right OperandBuilder) ConditionBuilder {
- return ConditionBuilder{
- operandList: []OperandBuilder{left, right},
- mode: greaterThanEqualCond,
- }
- }
- // GreaterThanEqual returns a ConditionBuilder representing the greater than
- // equal to clause of the two argument OperandBuilders. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the greater than equal to clause of the item
- // // attribute "foo" and the value 5
- // condition := expression.Name("foo").GreaterThanEqual(expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("foo").GreaterThanEqual(expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "foo >= :five"
- func (nb NameBuilder) GreaterThanEqual(right OperandBuilder) ConditionBuilder {
- return GreaterThanEqual(nb, right)
- }
- // GreaterThanEqual returns a ConditionBuilder representing the greater than
- // equal to clause of the two argument OperandBuilders. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the greater than equal to clause of the item
- // // attribute "foo" and the value 5
- // condition := expression.Value(5).GreaterThanEqual(expression.Name("foo"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Value(5).GreaterThanEqual(expression.Name("foo"))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // ":five >= foo"
- func (vb ValueBuilder) GreaterThanEqual(right OperandBuilder) ConditionBuilder {
- return GreaterThanEqual(vb, right)
- }
- // GreaterThanEqual returns a ConditionBuilder representing the greater than
- // equal to clause of the two argument OperandBuilders. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the greater than equal to clause of the size of
- // // the item attribute "foo" and the value 5
- // condition := expression.Size(expression.Name("foo")).GreaterThanEqual(expression.Value(5))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Size(expression.Name("foo")).GreaterThanEqual(expression.Value(5))
- // // Let :five be an ExpressionAttributeValue representing the value 5
- // "size (foo) >= :five"
- func (sb SizeBuilder) GreaterThanEqual(right OperandBuilder) ConditionBuilder {
- return GreaterThanEqual(sb, right)
- }
- // And returns a ConditionBuilder representing the logical AND clause of the
- // argument ConditionBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct. Note that And() can take a variadic number of
- // ConditionBuilders as arguments.
- //
- // Example:
- //
- // // condition represents the condition where the item attribute "Name" is
- // // equal to value "Generic Name" AND the item attribute "Age" is less
- // // than value 40
- // condition := expression.And(expression.Name("Name").Equal(expression.Value("Generic Name")), expression.Name("Age").LessThan(expression.Value(40)))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.And(expression.Name("Name").Equal(expression.Value("Generic Name")), expression.Name("Age").LessThan(expression.Value(40)))
- // // Let #NAME, :name, and :forty be ExpressionAttributeName and
- // // ExpressionAttributeValues representing the item attribute "Name", the
- // // value "Generic Name", and the value 40
- // "(#NAME = :name) AND (Age < :forty)"
- func And(left, right ConditionBuilder, other ...ConditionBuilder) ConditionBuilder {
- other = append([]ConditionBuilder{left, right}, other...)
- return ConditionBuilder{
- conditionList: other,
- mode: andCond,
- }
- }
- // And returns a ConditionBuilder representing the logical AND clause of the
- // argument ConditionBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct. Note that And() can take a variadic number of
- // ConditionBuilders as arguments.
- //
- // Example:
- //
- // // condition represents the condition where the item attribute "Name" is
- // // equal to value "Generic Name" AND the item attribute "Age" is less
- // // than value 40
- // condition := expression.Name("Name").Equal(expression.Value("Generic Name")).And(expression.Name("Age").LessThan(expression.Value(40)))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("Name").Equal(expression.Value("Generic Name")).And(expression.Name("Age").LessThan(expression.Value(40)))
- // // Let #NAME, :name, and :forty be ExpressionAttributeName and
- // // ExpressionAttributeValues representing the item attribute "Name", the
- // // value "Generic Name", and the value 40
- // "(#NAME = :name) AND (Age < :forty)"
- func (cb ConditionBuilder) And(right ConditionBuilder, other ...ConditionBuilder) ConditionBuilder {
- return And(cb, right, other...)
- }
- // Or returns a ConditionBuilder representing the logical OR clause of the
- // argument ConditionBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct. Note that Or() can take a variadic number of
- // ConditionBuilders as arguments.
- //
- // Example:
- //
- // // condition represents the condition where the item attribute "Price" is
- // // less than the value 100 OR the item attribute "Rating" is greater than
- // // the value 8
- // condition := expression.Or(expression.Name("Price").Equal(expression.Value(100)), expression.Name("Rating").LessThan(expression.Value(8)))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Or(expression.Name("Price").Equal(expression.Value(100)), expression.Name("Rating").LessThan(expression.Value(8)))
- // // Let :price and :rating be ExpressionAttributeValues representing the
- // // the value 100 and value 8 respectively
- // "(Price < :price) OR (Rating > :rating)"
- func Or(left, right ConditionBuilder, other ...ConditionBuilder) ConditionBuilder {
- other = append([]ConditionBuilder{left, right}, other...)
- return ConditionBuilder{
- conditionList: other,
- mode: orCond,
- }
- }
- // Or returns a ConditionBuilder representing the logical OR clause of the
- // argument ConditionBuilders. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct. Note that Or() can take a variadic number of
- // ConditionBuilders as arguments.
- //
- // Example:
- //
- // // condition represents the condition where the item attribute "Price" is
- // // less than the value 100 OR the item attribute "Rating" is greater than
- // // the value 8
- // condition := expression.Name("Price").Equal(expression.Value(100)).Or(expression.Name("Rating").LessThan(expression.Value(8)))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("Price").Equal(expression.Value(100)).Or(expression.Name("Rating").LessThan(expression.Value(8)))
- // // Let :price and :rating be ExpressionAttributeValues representing the
- // // the value 100 and value 8 respectively
- // "(Price < :price) OR (Rating > :rating)"
- func (cb ConditionBuilder) Or(right ConditionBuilder, other ...ConditionBuilder) ConditionBuilder {
- return Or(cb, right, other...)
- }
- // Not returns a ConditionBuilder representing the logical NOT clause of the
- // argument ConditionBuilder. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the condition where the item attribute "Name"
- // // does not begin with "test"
- // condition := expression.Not(expression.Name("Name").BeginsWith("test"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Not(expression.Name("Name").BeginsWith("test"))
- // // Let :prefix be an ExpressionAttributeValue representing the value
- // // "test"
- // "NOT (begins_with (:prefix))"
- func Not(conditionBuilder ConditionBuilder) ConditionBuilder {
- return ConditionBuilder{
- conditionList: []ConditionBuilder{conditionBuilder},
- mode: notCond,
- }
- }
- // Not returns a ConditionBuilder representing the logical NOT clause of the
- // argument ConditionBuilder. The resulting ConditionBuilder can be used as a
- // part of other Condition Expressions or as an argument to the WithCondition()
- // method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the condition where the item attribute "Name"
- // // does not begin with "test"
- // condition := expression.Name("Name").BeginsWith("test").Not()
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("Name").BeginsWith("test").Not()
- // // Let :prefix be an ExpressionAttributeValue representing the value
- // // "test"
- // "NOT (begins_with (:prefix))"
- func (cb ConditionBuilder) Not() ConditionBuilder {
- return Not(cb)
- }
- // Between returns a ConditionBuilder representing the result of the
- // BETWEEN function in DynamoDB Condition Expressions. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the condition where the value of the item
- // // attribute "Rating" is between values 5 and 10
- // condition := expression.Between(expression.Name("Rating"), expression.Value(5), expression.Value(10))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Between(expression.Name("Rating"), expression.Value(5), expression.Value(10))
- // // Let :five and :ten be ExpressionAttributeValues representing the value
- // // 5 and the value 10
- // "Rating BETWEEN :five AND :ten"
- func Between(op, lower, upper OperandBuilder) ConditionBuilder {
- return ConditionBuilder{
- operandList: []OperandBuilder{op, lower, upper},
- mode: betweenCond,
- }
- }
- // Between returns a ConditionBuilder representing the result of the
- // BETWEEN function in DynamoDB Condition Expressions. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the condition where the value of the item
- // // attribute "Rating" is between values 5 and 10
- // condition := expression.Name("Rating").Between(expression.Value(5), expression.Value(10))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("Rating").Between(expression.Value(5), expression.Value(10))
- // // Let :five and :ten be ExpressionAttributeValues representing the value
- // // 5 and the value 10
- // "Rating BETWEEN :five AND :ten"
- func (nb NameBuilder) Between(lower, upper OperandBuilder) ConditionBuilder {
- return Between(nb, lower, upper)
- }
- // Between returns a ConditionBuilder representing the result of the
- // BETWEEN function in DynamoDB Condition Expressions. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the condition where the value 6 is between values
- // // 5 and 10
- // condition := expression.Value(6).Between(expression.Value(5), expression.Value(10))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Value(6).Between(expression.Value(5), expression.Value(10))
- // // Let :six, :five and :ten be ExpressionAttributeValues representing the
- // // values 6, 5, and 10 respectively
- // ":six BETWEEN :five AND :ten"
- func (vb ValueBuilder) Between(lower, upper OperandBuilder) ConditionBuilder {
- return Between(vb, lower, upper)
- }
- // Between returns a ConditionBuilder representing the result of the
- // BETWEEN function in DynamoDB Condition Expressions. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the condition where the size of the item
- // // attribute "InviteList" is between values 5 and 10
- // condition := expression.Size(expression.Name("InviteList")).Between(expression.Value(5), expression.Value(10))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Size(expression.Name("InviteList")).Between(expression.Value(5), expression.Value(10))
- // // Let :five and :ten be ExpressionAttributeValues representing the value
- // // 5 and the value 10
- // "size (InviteList) BETWEEN :five AND :ten"
- func (sb SizeBuilder) Between(lower, upper OperandBuilder) ConditionBuilder {
- return Between(sb, lower, upper)
- }
- // In returns a ConditionBuilder representing the result of the IN function
- // in DynamoDB Condition Expressions. The resulting ConditionBuilder can be used
- // as a part of other Condition Expressions or as an argument to the
- // WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the condition where the value of the item
- // // attribute "Color" is checked against the list of colors "red",
- // // "green", and "blue".
- // condition := expression.In(expression.Name("Color"), expression.Value("red"), expression.Value("green"), expression.Value("blue"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.In(expression.Name("Color"), expression.Value("red"), expression.Value("green"), expression.Value("blue"))
- // // Let :red, :green, :blue be ExpressionAttributeValues representing the
- // // values "red", "green", and "blue" respectively
- // "Color IN (:red, :green, :blue)"
- func In(left, right OperandBuilder, other ...OperandBuilder) ConditionBuilder {
- other = append([]OperandBuilder{left, right}, other...)
- return ConditionBuilder{
- operandList: other,
- mode: inCond,
- }
- }
- // In returns a ConditionBuilder representing the result of the IN function
- // in DynamoDB Condition Expressions. The resulting ConditionBuilder can be used
- // as a part of other Condition Expressions or as an argument to the
- // WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the condition where the value of the item
- // // attribute "Color" is checked against the list of colors "red",
- // // "green", and "blue".
- // condition := expression.Name("Color").In(expression.Value("red"), expression.Value("green"), expression.Value("blue"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("Color").In(expression.Value("red"), expression.Value("green"), expression.Value("blue"))
- // // Let :red, :green, :blue be ExpressionAttributeValues representing the
- // // values "red", "green", and "blue" respectively
- // "Color IN (:red, :green, :blue)"
- func (nb NameBuilder) In(right OperandBuilder, other ...OperandBuilder) ConditionBuilder {
- return In(nb, right, other...)
- }
- // In returns a ConditionBuilder representing the result of the IN function
- // TODO change this one
- // in DynamoDB Condition Expressions. The resulting ConditionBuilder can be used
- // as a part of other Condition Expressions or as an argument to the
- // WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the condition where the value "yellow" is checked
- // // against the list of colors "red", "green", and "blue".
- // condition := expression.Value("yellow").In(expression.Value("red"), expression.Value("green"), expression.Value("blue"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Value("yellow").In(expression.Value("red"), expression.Value("green"), expression.Value("blue"))
- // // Let :yellow, :red, :green, :blue be ExpressionAttributeValues
- // // representing the values "yellow", "red", "green", and "blue"
- // // respectively
- // ":yellow IN (:red, :green, :blue)"
- func (vb ValueBuilder) In(right OperandBuilder, other ...OperandBuilder) ConditionBuilder {
- return In(vb, right, other...)
- }
- // In returns a ConditionBuilder representing the result of the IN function
- // in DynamoDB Condition Expressions. The resulting ConditionBuilder can be used
- // as a part of other Condition Expressions or as an argument to the
- // WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the condition where the size of the item
- // // attribute "Donuts" is checked against the list of numbers 12, 24, and
- // // 36.
- // condition := expression.Size(expression.Name("Donuts")).In(expression.Value(12), expression.Value(24), expression.Value(36))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Size(expression.Name("Donuts")).In(expression.Value(12), expression.Value(24), expression.Value(36))
- // // Let :dozen, :twoDozen, :threeDozen be ExpressionAttributeValues
- // // representing the values 12, 24, and 36 respectively
- // "size (Donuts) IN (12, 24, 36)"
- func (sb SizeBuilder) In(right OperandBuilder, other ...OperandBuilder) ConditionBuilder {
- return In(sb, right, other...)
- }
- // AttributeExists returns a ConditionBuilder representing the result of the
- // attribute_exists function in DynamoDB Condition Expressions. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the boolean condition of whether the item
- // // attribute "Age" exists or not
- // condition := expression.AttributeExists(expression.Name("Age"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.AttributeExists(expression.Name("Age"))
- // "attribute_exists (Age))"
- func AttributeExists(nameBuilder NameBuilder) ConditionBuilder {
- return ConditionBuilder{
- operandList: []OperandBuilder{nameBuilder},
- mode: attrExistsCond,
- }
- }
- // AttributeExists returns a ConditionBuilder representing the result of the
- // attribute_exists function in DynamoDB Condition Expressions. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the boolean condition of whether the item
- // // attribute "Age" exists or not
- // condition := expression.Name("Age").AttributeExists()
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("Age").AttributeExists()
- // "attribute_exists (Age))"
- func (nb NameBuilder) AttributeExists() ConditionBuilder {
- return AttributeExists(nb)
- }
- // AttributeNotExists returns a ConditionBuilder representing the result of
- // the attribute_not_exists function in DynamoDB Condition Expressions. The
- // resulting ConditionBuilder can be used as a part of other Condition
- // Expressions or as an argument to the WithCondition() method for the Builder
- // struct.
- //
- // Example:
- //
- // // condition represents the boolean condition of whether the item
- // // attribute "Age" exists or not
- // condition := expression.AttributeNotExists(expression.Name("Age"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.AttributeNotExists(expression.Name("Age"))
- // "attribute_not_exists (Age))"
- func AttributeNotExists(nameBuilder NameBuilder) ConditionBuilder {
- return ConditionBuilder{
- operandList: []OperandBuilder{nameBuilder},
- mode: attrNotExistsCond,
- }
- }
- // AttributeNotExists returns a ConditionBuilder representing the result of
- // the attribute_not_exists function in DynamoDB Condition Expressions. The
- // resulting ConditionBuilder can be used as a part of other Condition
- // Expressions or as an argument to the WithCondition() method for the Builder
- // struct.
- //
- // Example:
- //
- // // condition represents the boolean condition of whether the item
- // // attribute "Age" exists or not
- // condition := expression.Name("Age").AttributeNotExists()
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("Age").AttributeNotExists()
- // "attribute_not_exists (Age))"
- func (nb NameBuilder) AttributeNotExists() ConditionBuilder {
- return AttributeNotExists(nb)
- }
- // AttributeType returns a ConditionBuilder representing the result of the
- // attribute_type function in DynamoDB Condition Expressions. The DynamoDB types
- // are represented by the type DynamoDBAttributeType. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the boolean condition of whether the item
- // // attribute "Age" has the DynamoDB type Number or not
- // condition := expression.AttributeType(expression.Name("Age"), expression.Number)
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.AttributeType(expression.Name("Age"), expression.Number)
- // // Let :type be an ExpressionAttributeValue representing the value "N"
- // "attribute_type (Age, :type)"
- func AttributeType(nameBuilder NameBuilder, attributeType DynamoDBAttributeType) ConditionBuilder {
- v := ValueBuilder{
- value: string(attributeType),
- }
- return ConditionBuilder{
- operandList: []OperandBuilder{nameBuilder, v},
- mode: attrTypeCond,
- }
- }
- // AttributeType returns a ConditionBuilder representing the result of the
- // attribute_type function in DynamoDB Condition Expressions. The DynamoDB types
- // are represented by the type DynamoDBAttributeType. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the boolean condition of whether the item
- // // attribute "Age" has the DynamoDB type Number or not
- // condition := expression.Name("Age").AttributeType(expression.Number)
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("Age").AttributeType(expression.Number)
- // // Let :type be an ExpressionAttributeValue representing the value "N"
- // "attribute_type (Age, :type)"
- func (nb NameBuilder) AttributeType(attributeType DynamoDBAttributeType) ConditionBuilder {
- return AttributeType(nb, attributeType)
- }
- // BeginsWith returns a ConditionBuilder representing the result of the
- // begins_with function in DynamoDB Condition Expressions. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the boolean condition of whether the item
- // // attribute "CodeName" starts with the substring "Ben"
- // condition := expression.BeginsWith(expression.Name("CodeName"), "Ben")
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.BeginsWith(expression.Name("CodeName"), "Ben")
- // // Let :ben be an ExpressionAttributeValue representing the value "Ben"
- // "begins_with (CodeName, :ben)"
- func BeginsWith(nameBuilder NameBuilder, prefix string) ConditionBuilder {
- v := ValueBuilder{
- value: prefix,
- }
- return ConditionBuilder{
- operandList: []OperandBuilder{nameBuilder, v},
- mode: beginsWithCond,
- }
- }
- // BeginsWith returns a ConditionBuilder representing the result of the
- // begins_with function in DynamoDB Condition Expressions. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the boolean condition of whether the item
- // // attribute "CodeName" starts with the substring "Ben"
- // condition := expression.Name("CodeName").BeginsWith("Ben")
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("CodeName").BeginsWith("Ben")
- // // Let :ben be an ExpressionAttributeValue representing the value "Ben"
- // "begins_with (CodeName, :ben)"
- func (nb NameBuilder) BeginsWith(prefix string) ConditionBuilder {
- return BeginsWith(nb, prefix)
- }
- // Contains returns a ConditionBuilder representing the result of the
- // contains function in DynamoDB Condition Expressions. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the boolean condition of whether the item
- // // attribute "InviteList" has the value "Ben"
- // condition := expression.Contains(expression.Name("InviteList"), expression.Value("Ben"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Contains(expression.Name("InviteList"), expression.Value("Ben"))
- // // Let :ben be an ExpressionAttributeValue representing the value "Ben"
- // "contains (InviteList, :ben)"
- func Contains(nameBuilder NameBuilder, substr string) ConditionBuilder {
- v := ValueBuilder{
- value: substr,
- }
- return ConditionBuilder{
- operandList: []OperandBuilder{nameBuilder, v},
- mode: containsCond,
- }
- }
- // Contains returns a ConditionBuilder representing the result of the
- // contains function in DynamoDB Condition Expressions. The resulting
- // ConditionBuilder can be used as a part of other Condition Expressions or as
- // an argument to the WithCondition() method for the Builder struct.
- //
- // Example:
- //
- // // condition represents the boolean condition of whether the item
- // // attribute "InviteList" has the value "Ben"
- // condition := expression.Name("InviteList").Contains(expression.Value("Ben"))
- //
- // // Used in another Condition Expression
- // anotherCondition := expression.Not(condition)
- // // Used to make an Builder
- // builder := expression.NewBuilder().WithCondition(condition)
- //
- // Expression Equivalent:
- //
- // expression.Name("InviteList").Contains(expression.Value("Ben"))
- // // Let :ben be an ExpressionAttributeValue representing the value "Ben"
- // "contains (InviteList, :ben)"
- func (nb NameBuilder) Contains(substr string) ConditionBuilder {
- return Contains(nb, substr)
- }
- // buildTree builds a tree structure of exprNodes based on the tree
- // structure of the input ConditionBuilder's child ConditionBuilders and
- // OperandBuilders. buildTree() satisfies the treeBuilder interface so
- // ConditionBuilder can be a part of Builder and Expression struct.
- func (cb ConditionBuilder) buildTree() (exprNode, error) {
- childNodes, err := cb.buildChildNodes()
- if err != nil {
- return exprNode{}, err
- }
- ret := exprNode{
- children: childNodes,
- }
- switch cb.mode {
- case equalCond, notEqualCond, lessThanCond, lessThanEqualCond, greaterThanCond, greaterThanEqualCond:
- return compareBuildCondition(cb.mode, ret)
- case andCond, orCond:
- return compoundBuildCondition(cb, ret)
- case notCond:
- return notBuildCondition(ret)
- case betweenCond:
- return betweenBuildCondition(ret)
- case inCond:
- return inBuildCondition(cb, ret)
- case attrExistsCond:
- return attrExistsBuildCondition(ret)
- case attrNotExistsCond:
- return attrNotExistsBuildCondition(ret)
- case attrTypeCond:
- return attrTypeBuildCondition(ret)
- case beginsWithCond:
- return beginsWithBuildCondition(ret)
- case containsCond:
- return containsBuildCondition(ret)
- case unsetCond:
- return exprNode{}, newUnsetParameterError("buildTree", "ConditionBuilder")
- default:
- return exprNode{}, fmt.Errorf("build condition error: unsupported mode: %v", cb.mode)
- }
- }
- // compareBuildCondition is the function to make exprNodes from Compare
- // ConditionBuilders. compareBuildCondition is only called by the
- // buildTree method. This function assumes that the argument ConditionBuilder
- // has the right format.
- func compareBuildCondition(conditionMode conditionMode, node exprNode) (exprNode, error) {
- // Create a string with special characters that can be substituted later: $c
- switch conditionMode {
- case equalCond:
- node.fmtExpr = "$c = $c"
- case notEqualCond:
- node.fmtExpr = "$c <> $c"
- case lessThanCond:
- node.fmtExpr = "$c < $c"
- case lessThanEqualCond:
- node.fmtExpr = "$c <= $c"
- case greaterThanCond:
- node.fmtExpr = "$c > $c"
- case greaterThanEqualCond:
- node.fmtExpr = "$c >= $c"
- default:
- return exprNode{}, fmt.Errorf("build compare condition error: unsupported mode: %v", conditionMode)
- }
- return node, nil
- }
- // compoundBuildCondition is the function to make exprNodes from And/Or
- // ConditionBuilders. compoundBuildCondition is only called by the
- // buildTree method. This function assumes that the argument ConditionBuilder
- // has the right format.
- func compoundBuildCondition(conditionBuilder ConditionBuilder, node exprNode) (exprNode, error) {
- // create a string with escaped characters to substitute them with proper
- // aliases during runtime
- var mode string
- switch conditionBuilder.mode {
- case andCond:
- mode = " AND "
- case orCond:
- mode = " OR "
- default:
- return exprNode{}, fmt.Errorf("build compound condition error: unsupported mode: %v", conditionBuilder.mode)
- }
- node.fmtExpr = "($c)" + strings.Repeat(mode+"($c)", len(conditionBuilder.conditionList)-1)
- return node, nil
- }
- // notBuildCondition is the function to make exprNodes from Not
- // ConditionBuilders. notBuildCondition is only called by the
- // buildTree method. This function assumes that the argument ConditionBuilder
- // has the right format.
- func notBuildCondition(node exprNode) (exprNode, error) {
- // create a string with escaped characters to substitute them with proper
- // aliases during runtime
- node.fmtExpr = "NOT ($c)"
- return node, nil
- }
- // betweenBuildCondition is the function to make exprNodes from Between
- // ConditionBuilders. BuildCondition is only called by the
- // buildTree method. This function assumes that the argument ConditionBuilder
- // has the right format.
- func betweenBuildCondition(node exprNode) (exprNode, error) {
- // Create a string with special characters that can be substituted later: $c
- node.fmtExpr = "$c BETWEEN $c AND $c"
- return node, nil
- }
- // inBuildCondition is the function to make exprNodes from In
- // ConditionBuilders. inBuildCondition is only called by the
- // buildTree method. This function assumes that the argument ConditionBuilder
- // has the right format.
- func inBuildCondition(conditionBuilder ConditionBuilder, node exprNode) (exprNode, error) {
- // Create a string with special characters that can be substituted later: $c
- node.fmtExpr = "$c IN ($c" + strings.Repeat(", $c", len(conditionBuilder.operandList)-2) + ")"
- return node, nil
- }
- // attrExistsBuildCondition is the function to make exprNodes from
- // AttrExistsCond ConditionBuilders. attrExistsBuildCondition is only
- // called by the buildTree method. This function assumes that the argument
- // ConditionBuilder has the right format.
- func attrExistsBuildCondition(node exprNode) (exprNode, error) {
- // Create a string with special characters that can be substituted later: $c
- node.fmtExpr = "attribute_exists ($c)"
- return node, nil
- }
- // attrNotExistsBuildCondition is the function to make exprNodes from
- // AttrNotExistsCond ConditionBuilders. attrNotExistsBuildCondition is only
- // called by the buildTree method. This function assumes that the argument
- // ConditionBuilder has the right format.
- func attrNotExistsBuildCondition(node exprNode) (exprNode, error) {
- // Create a string with special characters that can be substituted later: $c
- node.fmtExpr = "attribute_not_exists ($c)"
- return node, nil
- }
- // attrTypeBuildCondition is the function to make exprNodes from AttrTypeCond
- // ConditionBuilders. attrTypeBuildCondition is only called by the
- // buildTree method. This function assumes that the argument
- // ConditionBuilder has the right format.
- func attrTypeBuildCondition(node exprNode) (exprNode, error) {
- // Create a string with special characters that can be substituted later: $c
- node.fmtExpr = "attribute_type ($c, $c)"
- return node, nil
- }
- // beginsWithBuildCondition is the function to make exprNodes from
- // BeginsWithCond ConditionBuilders. beginsWithBuildCondition is only
- // called by the buildTree method. This function assumes that the argument
- // ConditionBuilder has the right format.
- func beginsWithBuildCondition(node exprNode) (exprNode, error) {
- // Create a string with special characters that can be substituted later: $c
- node.fmtExpr = "begins_with ($c, $c)"
- return node, nil
- }
- // containsBuildCondition is the function to make exprNodes from
- // ContainsCond ConditionBuilders. containsBuildCondition is only
- // called by the buildTree method. This function assumes that the argument
- // ConditionBuilder has the right format.
- func containsBuildCondition(node exprNode) (exprNode, error) {
- // Create a string with special characters that can be substituted later: $c
- node.fmtExpr = "contains ($c, $c)"
- return node, nil
- }
- // buildChildNodes creates the list of the child exprNodes. This avoids
- // duplication of code amongst the various buildTree functions.
- func (cb ConditionBuilder) buildChildNodes() ([]exprNode, error) {
- childNodes := make([]exprNode, 0, len(cb.conditionList)+len(cb.operandList))
- for _, condition := range cb.conditionList {
- node, err := condition.buildTree()
- if err != nil {
- return []exprNode{}, err
- }
- childNodes = append(childNodes, node)
- }
- for _, ope := range cb.operandList {
- operand, err := ope.BuildOperand()
- if err != nil {
- return []exprNode{}, err
- }
- childNodes = append(childNodes, operand.exprNode)
- }
- return childNodes, nil
- }
|