Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): support for "begins_with" operator searches #196

Merged
merged 10 commits into from
Feb 1, 2022
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
node_modules
yarn.lock
.idea/
.vscode/
.npmrc
26 changes: 23 additions & 3 deletions lib/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ exports.createServer = (dynamodb, docClient) => {
}
}


if (secondaryIndex.IndexType === 'global') {
index.ProvisionedThroughput = {
ReadCapacityUnits: req.body.ReadCapacityUnits,
Expand Down Expand Up @@ -400,6 +399,7 @@ exports.createServer = (dynamodb, docClient) => {
'<=': '<=',
'>': '>',
'<': '<',
'begins_with': 'begins_with'
},
attributeTypes: {
'S': 'String',
Expand Down Expand Up @@ -450,11 +450,30 @@ exports.createServer = (dynamodb, docClient) => {
if (indexBeingUsed && indexBeingUsed.KeySchema.find(
(keySchemaItem) => keySchemaItem.AttributeName === key)
) {
KeyConditionExpression.push(`#key${i} ${filters[key].operator} :key${i}`)
const matchedKeySchema = indexBeingUsed.KeySchema.find(
(keySchemaItem) => keySchemaItem.AttributeName === key)

if (matchedKeySchema.KeyType === 'HASH') {
KeyConditionExpression.push(
`#key${i} ${filters[key].operator} :key${i}`)
} else if (matchedKeySchema.KeyType === 'RANGE') {
if (filters[key].operator === 'begins_with') {
KeyConditionExpression.push(
`${filters[key].operator} ( #key${i} , :key${i})`)
} else {
KeyConditionExpression.push(
`#key${i} ${filters[key].operator} :key${i}`)
}
}
rchl marked this conversation as resolved.
Show resolved Hide resolved
} else {
ExpressionAttributeNames[`#key${i}`] = key
ExpressionAttributeValues[`:key${i}`] = filters[key].value
FilterExpressions.push(`#key${i} ${filters[key].operator} :key${i}`)

if (filters[key].operator === 'begins_with') {
FilterExpressions.push(`${filters[key].operator} ( #key${i} , :key${i})`)
} else {
FilterExpressions.push(`#key${i} ${filters[key].operator} :key${i}`)
}
}
// Increment the unique ID variable
i = i + 1
Expand Down Expand Up @@ -658,6 +677,7 @@ exports.createServer = (dynamodb, docClient) => {

return app
}

function isAttributeNotAlreadyCreated(attributeDefinitions, attributeName) {
return !attributeDefinitions
.find(attributeDefinition => attributeDefinition.AttributeName === attributeName)
Expand Down
61 changes: 22 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.