@ginger.io/beyonce
Advanced tools
Comparing version 0.0.46 to 0.0.47
export declare class Attributes { | ||
private substitutions; | ||
add(attribute: string): string; | ||
getSubstitutions(): Readonly<{ | ||
getSubstitutions(): { | ||
[key: string]: string; | ||
}>; | ||
}; | ||
} |
@@ -14,3 +14,3 @@ "use strict"; | ||
getSubstitutions() { | ||
return this.substitutions; | ||
return Object.assign({}, this.substitutions); | ||
} | ||
@@ -17,0 +17,0 @@ } |
@@ -19,7 +19,8 @@ import { KeysOf } from "../../typeUtils"; | ||
andAttributeNotExists(name: KeysOf<T>): this; | ||
build(): DynamoDBExpression; | ||
protected addAttributeName(name: string): string; | ||
protected addAttributeValue(name: string, value: any): string; | ||
protected addAttributeValue(value: any): string; | ||
protected addStatement(statement: string): void; | ||
build(): DynamoDBExpression; | ||
protected reset(): void; | ||
private addCondition; | ||
} |
@@ -55,11 +55,2 @@ "use strict"; | ||
} | ||
addAttributeName(name) { | ||
return this.attributeNames.add(name); | ||
} | ||
addAttributeValue(name, value) { | ||
return this.attributeValues.add(name, value); | ||
} | ||
addStatement(statement) { | ||
this.statements.push(statement); | ||
} | ||
build() { | ||
@@ -75,5 +66,19 @@ const expression = this.statements.join(" "); | ||
} | ||
addAttributeName(name) { | ||
return this.attributeNames.add(name); | ||
} | ||
addAttributeValue(value) { | ||
return this.attributeValues.add(value); | ||
} | ||
addStatement(statement) { | ||
this.statements.push(statement); | ||
} | ||
reset() { | ||
this.attributeNames = new Attributes_1.Attributes(); | ||
this.attributeValues = new Variables_1.Variables(); | ||
this.statements = []; | ||
} | ||
addCondition(params) { | ||
const attributePlaceholder = this.addAttributeName(params.attribute); | ||
const valuePlaceholder = this.addAttributeValue(params.attribute, params.value); | ||
const valuePlaceholder = this.addAttributeValue(params.value); | ||
const expression = []; | ||
@@ -80,0 +85,0 @@ if (params.booleanOperator !== undefined) { |
@@ -14,3 +14,3 @@ import { PartitionAndSortKey } from "../keys"; | ||
protected addAttributeName(name: string): string; | ||
protected addAttributeValue(name: string, value: any): string; | ||
protected addAttributeValue(value: any): string; | ||
} |
@@ -15,3 +15,3 @@ "use strict"; | ||
const attrPlaceholders = attributePath.map((attr) => this.addAttributeName(attr)); | ||
const valuePlaceholder = this.addAttributeValue(attributePath[attributePath.length - 1], value); | ||
const valuePlaceholder = this.addAttributeValue(value); | ||
this.setStatements.push(`${attrPlaceholders.join(".")} = ${valuePlaceholder}`); | ||
@@ -27,7 +27,7 @@ return this; | ||
const pkPlaceholder = this.addAttributeName(key.partitionKeyName); | ||
const pkValuePlaceholder = this.addAttributeValue(key.partitionKeyName, key.partitionKey); | ||
const pkValuePlaceholder = this.addAttributeValue(key.partitionKey); | ||
const keyConditionExpression = [`${pkPlaceholder} = ${pkValuePlaceholder}`]; | ||
const { sortKeyName, sortKey } = key; | ||
const skPlaceholder = this.addAttributeName(sortKeyName); | ||
const skValuePlaceholder = this.addAttributeValue(sortKeyName, sortKey); | ||
const skValuePlaceholder = this.addAttributeValue(sortKey); | ||
keyConditionExpression.push(`begins_with(${skPlaceholder}, ${skValuePlaceholder})`); | ||
@@ -55,4 +55,4 @@ return keyConditionExpression.join(" AND "); | ||
} | ||
addAttributeValue(name, value) { | ||
return this.attributeValues.add(name, value); | ||
addAttributeValue(value) { | ||
return this.attributeValues.add(value); | ||
} | ||
@@ -59,0 +59,0 @@ } |
export declare class Variables { | ||
private substitutions; | ||
add(name: string, value: any): string; | ||
getSubstitutions(): Readonly<{ | ||
private counter; | ||
add(value: any): string; | ||
getSubstitutions(): { | ||
[key: string]: string; | ||
}>; | ||
}; | ||
} |
@@ -7,10 +7,12 @@ "use strict"; | ||
this.substitutions = {}; | ||
this.counter = 1; | ||
} | ||
add(name, value) { | ||
const placeholder = `:${name}`; | ||
add(value) { | ||
const placeholder = `:v${this.counter}`; | ||
this.substitutions[placeholder] = value; | ||
this.counter += 1; | ||
return placeholder; | ||
} | ||
getSubstitutions() { | ||
return this.substitutions; | ||
return Object.assign({}, this.substitutions); | ||
} | ||
@@ -17,0 +19,0 @@ } |
@@ -80,2 +80,3 @@ "use strict"; | ||
buildQuery(options) { | ||
let query; | ||
if (isTableQuery(this.config)) { | ||
@@ -86,3 +87,3 @@ const { table, consistentRead } = this.config; | ||
const filterExp = expression !== "" ? expression : undefined; | ||
return { | ||
query = { | ||
TableName: table.tableName, | ||
@@ -104,3 +105,3 @@ ConsistentRead: consistentRead, | ||
const filterExp = expression !== "" ? expression : undefined; | ||
return { | ||
query = { | ||
TableName: table.tableName, | ||
@@ -118,2 +119,4 @@ ConsistentRead: consistentRead, | ||
} | ||
this.reset(); | ||
return query; | ||
} | ||
@@ -123,3 +126,3 @@ buildKeyConditionForTable(config) { | ||
const pkPlaceholder = this.addAttributeName(key.partitionKeyName); | ||
const pkValuePlaceholder = this.addAttributeValue(key.partitionKeyName, key.partitionKey); | ||
const pkValuePlaceholder = this.addAttributeValue(key.partitionKey); | ||
const keyConditionExpression = [`${pkPlaceholder} = ${pkValuePlaceholder}`]; | ||
@@ -129,3 +132,3 @@ if (isPartitionKeyWithSortKeyPrefix(key)) { | ||
const skPlaceholder = this.addAttributeName(sortKeyName); | ||
const skValuePlaceholder = this.addAttributeValue(sortKeyName, sortKeyPrefix); | ||
const skValuePlaceholder = this.addAttributeValue(sortKeyPrefix); | ||
keyConditionExpression.push(`begins_with(${skPlaceholder}, ${skValuePlaceholder})`); | ||
@@ -138,3 +141,3 @@ } | ||
const pkPlaceholder = this.addAttributeName(gsiKey.partitionKeyName); | ||
const pkValuePlaceholder = this.addAttributeValue(gsiKey.partitionKeyName, gsiKey.partitionKey); | ||
const pkValuePlaceholder = this.addAttributeValue(gsiKey.partitionKey); | ||
return `${pkPlaceholder} = ${pkValuePlaceholder}`; | ||
@@ -141,0 +144,0 @@ } |
@@ -80,3 +80,3 @@ "use strict"; | ||
const includeAttributeValues = filterExp !== undefined && Object.values(attributeValues).length > 0; | ||
return { | ||
const scan = { | ||
TableName: table.tableName, | ||
@@ -96,2 +96,4 @@ ConsistentRead: consistentRead, | ||
}; | ||
this.reset(); | ||
return scan; | ||
} | ||
@@ -98,0 +100,0 @@ } |
{ | ||
"name": "@ginger.io/beyonce", | ||
"version": "0.0.46", | ||
"version": "0.0.47", | ||
"description": "Type-safe DynamoDB query builder for TypeScript. Designed with single-table architecture in mind.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
146562
1868