Skip to content

Instantly share code, notes, and snippets.

@thobson
Created June 16, 2023 15:26
Show Gist options
  • Save thobson/841ca6598a390eb1bd3644ac916eb435 to your computer and use it in GitHub Desktop.
Save thobson/841ca6598a390eb1bd3644ac916eb435 to your computer and use it in GitHub Desktop.
import { Entity } from "electrodb";
import { client, table } from "../client";
export const UserEntity = new Entity(
{
model: {
version: "1",
entity: "user",
service: "default",
},
attributes: {
userId: {
type: "string",
required: true,
readOnly: true,
},
firstName: {
type: "string",
required: true
}
},
indexes: {
primary: {
collection: "overview",
pk: {
field: "pk",
composite: ["userId"],
},
sk: {
field: "sk",
composite: [],
},
}
}
},
{ client, table }
);
export const ItemEntity = new Entity(
{
model: {
version: "1",
entity: "user",
service: "default",
},
attributes: {
userId: {
type: "string",
required: true,
readOnly: true,
},
itemId: {
type: "string",
required: true,
readOnly: true,
},
itemName: {
type: "string",
required: true
}
},
indexes: {
primary: {
collection: "overview",
pk: {
field: "pk",
composite: ["userId"],
},
sk: {
field: "sk",
composite: ["itemId"],
},
}
}
},
{ client, table }
);
export const ImageEntity = new Entity(
{
model: {
version: "1",
entity: "user",
service: "default",
},
attributes: {
userId: {
type: "string",
required: true,
readOnly: true,
},
imageId: {
type: "string",
required: true,
readOnly: true,
},
key: {
type: "string",
required: true
}
},
indexes: {
primary: {
collection: "overview",
pk: {
field: "pk",
composite: ["userId"],
},
sk: {
field: "sk",
composite: ["imageId"],
},
}
}
},
{ client, table }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment