-
Notifications
You must be signed in to change notification settings - Fork 57
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
[Feature Request] Required container attributes can have empty values #177
Comments
For context, are you speaking about something like this? /* Model queries, see results, share with friends */
import { Entity, Service } from "electrodb";
const table = "your_table_name";
/* Tasks Entity */
const listHolder = new Entity(
{
model: {
entity: "listHolder",
version: "1",
service: "app"
},
attributes: {
id: {
type: 'string',
required: true,
},
set: {
type: 'set',
items: 'string',
required: true,
default: [],
},
},
indexes: {
main: {
pk: {
field: 'pk',
composite: ['id'],
}
}
}
},
{ table }
);
async function demonstrateIssue() {
await listHolder
.create({ id: 'example', set: [] })
.go();
const { data } = await listHolder
.get({ id: 'example' })
.go();
if (!data) return;
console.log(data.set.length); // TypeError: Cannot read property 'length' of undefined
} This one got me today. |
Our workaround:
Note that
It's weird that the document client allows empty strings, but doesn't allow empty sets, even though it's possible to add empty sets manually in AWS. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modelling empty lists and sets by omitting the property is understandable from a storage perspective, but adds overhead to the business logic consuming the objects. As a modelling layer over DynamoDB, ElectroDB could abstract this storage requirement away.
Feature Request – The
required
property of list and set attributes should allow empty sets and lists, marshalling to and from null behind the scenes.The text was updated successfully, but these errors were encountered: