Inverses and Cross Shard Foreign Keys
Ents with Random Shard Affinity
export class EntUser extends BaseEnt(
cluster,
new PgSchema("users", {
id: { type: ID, autoInsert: "id_gen()" },
...
}),
) {
static override configure() {
return new this.Configuration({
shardAffinity: [],
...
});
}
}
export class EntTopic extends BaseEnt(
cluster,
new PgSchema("topics", {
id: { type: ID, autoInsert: "id_gen()" },
// Reference to parent 1.
creator_id: { type: ID },
// Reference to parent 2 (optional).
last_commenter_id: { type: ID, allowNull: true },
...
}),
) {
static override configure() {
return new this.Configuration({
shardAffinity: [],
inverses: {
creator_id: { name: "inverses", type: "topic2creators" },
last_commenter_id: { name: "inverses", type: "topic2last_commenters" },
},
...
});
}
}
export class EntComment extends BaseEnt(
cluster,
new PgSchema("comments", {
id: { type: ID, autoInsert: "id_gen()" },
// Reference to parent.
topic_id: { type: ID },
...
}),
) {
static override configure() {
return new this.Configuration({
shardAffinity: [],
inverses: {
topic_id: { name: "inverses", type: "comment2topics" },
},
...
});
}
}SQL Tables for Inverses
An Example of What's Actually Inserted
Children Ent Microshard Hints
Unique Keys
Last updated