sam-goodwin / eventual

Build scalable and durable micro-services with APIs, Messaging and Workflows
https://docs.eventual.ai
MIT License
174 stars 4 forks source link

feat: entity index #348

Closed thantos closed 1 year ago

thantos commented 1 year ago

Add index support for entities. Also upgraded ts-jest (they don't support semantic versioning and the latest version is the first that supports typescript 5).

const myEntity = entity("myEntity", {
    attributes: {
       pk: z.string(),
       pk2: z.string(),
       field1: z.number(),
       field2: z.number(),
    },
    partition: ["pk", "pk2"]
});

// create a GSI with pk as the only key part.
const index1 = myEntity.index("index1", {
    partition: ["pk1"]
});

// create a GSI with the original partition key [pk, pk2]
// NOTE: tables without a sort key cannot have LSIs
const index2 = myEntity.index("index2", {
    sort: ["field1"]
});

// create a GSI with the partition key [pk], ordered by field1
const index3 = myEntity.index("index3", {
    partition: ["pk1"],
    sort: ["field1"]
});

const myEntity = entity("myEntity", {
    attributes: {
       pk: z.string(),
       pk2: z.string(),
       field1: z.number(),
       field2: z.number(),
    },
    partition: ["pk", "pk2"],
    sort: ["field1"]
});

// create a GSI with pk as the only key part.
const index1 = myEntity.index("index1", {
    partition: ["pk1"]
});

// create a LSI with the original partition key [pk, pk2]
const index2 = myEntity.index("index2", {
    sort: ["field1"]
});

// create a GSI with the partition key [pk], ordered by field1
const index3 = myEntity.index("index3", {
    partition: ["pk1"],
    sort: ["field1"]
});
sam-goodwin commented 1 year ago

Do we differentiate between GSI and LSI? Is that implicit based on key or explicit?

sam-goodwin commented 1 year ago

Do we differentiate between GSI and LSI? Is that implicit based on key or explicit?

Oh never mind, lol, it's in the description