Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions site/src/demo/schema/customers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { expose } from "typegres";
import { Relation, expose } from "typegres";
import { Int8, Text } from "typegres/postgres";
import { db } from "../runtime";
import { Orders } from "./orders";
import { Organizations } from "./organizations";
export class Customers extends db.Table("customers", { live: true }) {
// @generated-start
@expose() id = (Int8<1>).column({ nonNull: true, generated: true });
@expose() organization_id = (Int8<1>).column({ nonNull: true });
@expose() name = (Text<1>).column({ nonNull: true });
@expose() email = (Text<1>).column({ nonNull: true });
@expose() id = Int8.column({ nonNull: true, generated: true });
@expose() organization_id = Int8.column({ nonNull: true });
@expose() name = Text.column({ nonNull: true });
@expose() email = Text.column({ nonNull: true });
// relations
@expose() organization() { return Organizations.scope(Customers.contextOf(this)).where(({ organizations }) => organizations.id["="](this.organization_id)).cardinality("one"); }
@expose() orders() { return Orders.scope(Customers.contextOf(this)).where(({ orders }) => orders.customer_id["="](this.id)).cardinality("many"); }
@expose() organization() { return Relation.belongsTo(this, Organizations, { id: this.organization_id }); }
@expose() orders() { return Relation.has(this, Orders, { customer_id: this.id }); }
// @generated-end
}
20 changes: 10 additions & 10 deletions site/src/demo/schema/inventory_positions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Connection, sql, expose } from "typegres";
import { Relation, Connection, sql, expose } from "typegres";
import { Int8, Text } from "typegres/postgres";
import { z } from "zod";
import { db } from "../runtime";
Expand All @@ -7,16 +7,16 @@ import { Organizations } from "./organizations";
import { OrderLines } from "./order_lines";
export class InventoryPositions extends db.Table("inventory_positions", { live: true }) {
// @generated-start
@expose() id = (Int8<1>).column({ nonNull: true, generated: true });
@expose() organization_id = (Int8<1>).column({ nonNull: true });
@expose() location_id = (Int8<1>).column({ nonNull: true });
@expose() sku = (Text<1>).column({ nonNull: true });
@expose() on_hand = (Int8<1>).column({ nonNull: true, default: sql`0` });
@expose() reserved = (Int8<1>).column({ nonNull: true, default: sql`0` });
@expose() id = Int8.column({ nonNull: true, generated: true });
@expose() organization_id = Int8.column({ nonNull: true });
@expose() location_id = Int8.column({ nonNull: true });
@expose() sku = Text.column({ nonNull: true });
@expose() on_hand = Int8.column({ nonNull: true, default: sql`0` });
@expose() reserved = Int8.column({ nonNull: true, default: sql`0` });
// relations
@expose() location() { return Locations.scope(InventoryPositions.contextOf(this)).where(({ locations }) => locations.id["="](this.location_id)).cardinality("one"); }
@expose() organization() { return Organizations.scope(InventoryPositions.contextOf(this)).where(({ organizations }) => organizations.id["="](this.organization_id)).cardinality("one"); }
@expose() order_lines() { return OrderLines.scope(InventoryPositions.contextOf(this)).where(({ order_lines }) => order_lines.inventory_position_id["="](this.id)).cardinality("many"); }
@expose() location() { return Relation.belongsTo(this, Locations, { id: this.location_id }); }
@expose() organization() { return Relation.belongsTo(this, Organizations, { id: this.organization_id }); }
@expose() order_lines() { return Relation.has(this, OrderLines, { inventory_position_id: this.id }); }
// @generated-end

// inventory_control-only: adjust on_hand by a signed delta.
Expand Down
14 changes: 7 additions & 7 deletions site/src/demo/schema/locations.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { expose } from "typegres";
import { Relation, expose } from "typegres";
import { Int8, Text } from "typegres/postgres";
import { db } from "../runtime";
import { InventoryPositions } from "./inventory_positions";
import { Organizations } from "./organizations";

export class Locations extends db.Table("locations", { live: true }) {
// @generated-start
@expose() id = (Int8<1>).column({ nonNull: true, generated: true });
@expose() organization_id = (Int8<1>).column({ nonNull: true });
@expose() code = (Text<1>).column({ nonNull: true });
@expose() name = (Text<1>).column({ nonNull: true });
@expose() id = Int8.column({ nonNull: true, generated: true });
@expose() organization_id = Int8.column({ nonNull: true });
@expose() code = Text.column({ nonNull: true });
@expose() name = Text.column({ nonNull: true });
// relations
@expose() organization() { return Organizations.scope(Locations.contextOf(this)).where(({ organizations }) => organizations.id["="](this.organization_id)).cardinality("one"); }
@expose() inventory_positions() { return InventoryPositions.scope(Locations.contextOf(this)).where(({ inventory_positions }) => inventory_positions.location_id["="](this.id)).cardinality("many"); }
@expose() organization() { return Relation.belongsTo(this, Organizations, { id: this.organization_id }); }
@expose() inventory_positions() { return Relation.has(this, InventoryPositions, { location_id: this.id }); }
// @generated-end
}
16 changes: 8 additions & 8 deletions site/src/demo/schema/order_lines.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { expose } from "typegres";
import { Relation, expose } from "typegres";
import { Int8, Text } from "typegres/postgres";
import { db } from "../runtime";
import { InventoryPositions } from "./inventory_positions";
import { Orders } from "./orders";

export class OrderLines extends db.Table("order_lines", { live: true }) {
// @generated-start
@expose() id = (Int8<1>).column({ nonNull: true, generated: true });
@expose() order_id = (Int8<1>).column({ nonNull: true });
@expose() sku = (Text<1>).column({ nonNull: true });
@expose() quantity = (Int8<1>).column({ nonNull: true });
@expose() inventory_position_id = (Int8<0 | 1>).column();
@expose() id = Int8.column({ nonNull: true, generated: true });
@expose() order_id = Int8.column({ nonNull: true });
@expose() sku = Text.column({ nonNull: true });
@expose() quantity = Int8.column({ nonNull: true });
@expose() inventory_position_id = Int8.column();
// relations
@expose() inventory_position() { return InventoryPositions.scope(OrderLines.contextOf(this)).where(({ inventory_positions }) => inventory_positions.id["="](this.inventory_position_id)).cardinality("maybe"); }
@expose() order() { return Orders.scope(OrderLines.contextOf(this)).where(({ orders }) => orders.id["="](this.order_id)).cardinality("one"); }
@expose() inventory_position() { return Relation.belongsTo(this, InventoryPositions, { id: this.inventory_position_id }, { card: "maybe" }); }
@expose() order() { return Relation.belongsTo(this, Orders, { id: this.order_id }); }
// @generated-end
}
24 changes: 12 additions & 12 deletions site/src/demo/schema/orders.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Connection, sql, expose } from "typegres";
import { Relation, Connection, sql, expose } from "typegres";
import { Int8, Text, Timestamptz } from "typegres/postgres";
import { z } from "zod";
import { db } from "../runtime";
Expand All @@ -9,18 +9,18 @@ import { Shipments } from "./shipments";

export class Orders extends db.Table("orders", { live: true }) {
// @generated-start
@expose() id = (Int8<1>).column({ nonNull: true, generated: true });
@expose() organization_id = (Int8<1>).column({ nonNull: true });
@expose() customer_id = (Int8<1>).column({ nonNull: true });
@expose() status = (Text<1>).column({ nonNull: true, default: sql`'draft'::text` });
@expose() priority = (Int8<1>).column({ nonNull: true, default: sql`0` });
@expose() ship_by = (Timestamptz<0 | 1>).column();
@expose() created_at = (Timestamptz<1>).column({ nonNull: true, default: sql`now()` });
@expose() id = Int8.column({ nonNull: true, generated: true });
@expose() organization_id = Int8.column({ nonNull: true });
@expose() customer_id = Int8.column({ nonNull: true });
@expose() status = Text.column({ nonNull: true, default: sql`'draft'::text` });
@expose() priority = Int8.column({ nonNull: true, default: sql`0` });
@expose() ship_by = Timestamptz.column();
@expose() created_at = Timestamptz.column({ nonNull: true, default: sql`now()` });
// relations
@expose() customer() { return Customers.scope(Orders.contextOf(this)).where(({ customers }) => customers.id["="](this.customer_id)).cardinality("one"); }
@expose() organization() { return Organizations.scope(Orders.contextOf(this)).where(({ organizations }) => organizations.id["="](this.organization_id)).cardinality("one"); }
@expose() order_lines() { return OrderLines.scope(Orders.contextOf(this)).where(({ order_lines }) => order_lines.order_id["="](this.id)).cardinality("many"); }
@expose() shipments() { return Shipments.scope(Orders.contextOf(this)).where(({ shipments }) => shipments.order_id["="](this.id)).cardinality("many"); }
@expose() customer() { return Relation.belongsTo(this, Customers, { id: this.customer_id }); }
@expose() organization() { return Relation.belongsTo(this, Organizations, { id: this.organization_id }); }
@expose() order_lines() { return Relation.has(this, OrderLines, { order_id: this.id }); }
@expose() shipments() { return Relation.has(this, Shipments, { order_id: this.id }); }
// @generated-end

// ops_lead-only: advance this order one step along the lifecycle
Expand Down
20 changes: 10 additions & 10 deletions site/src/demo/schema/organizations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expose } from "typegres";
import { Relation, expose } from "typegres";
import { Int8, Text } from "typegres/postgres";
import { db } from "../runtime";
import { Customers } from "./customers";
Expand All @@ -9,15 +9,15 @@ import { Orders } from "./orders";
import { Shipments } from "./shipments";
export class Organizations extends db.Table("organizations", { live: true }) {
// @generated-start
@expose() id = (Int8<1>).column({ nonNull: true, generated: true });
@expose() name = (Text<1>).column({ nonNull: true });
@expose() slug = (Text<1>).column({ nonNull: true });
@expose() id = Int8.column({ nonNull: true, generated: true });
@expose() name = Text.column({ nonNull: true });
@expose() slug = Text.column({ nonNull: true });
// relations
@expose() customers() { return Customers.scope(Organizations.contextOf(this)).where(({ customers }) => customers.organization_id["="](this.id)).cardinality("many"); }
@expose() inventory_positions() { return InventoryPositions.scope(Organizations.contextOf(this)).where(({ inventory_positions }) => inventory_positions.organization_id["="](this.id)).cardinality("many"); }
@expose() locations() { return Locations.scope(Organizations.contextOf(this)).where(({ locations }) => locations.organization_id["="](this.id)).cardinality("many"); }
@expose() orders() { return Orders.scope(Organizations.contextOf(this)).where(({ orders }) => orders.organization_id["="](this.id)).cardinality("many"); }
@expose() shipments() { return Shipments.scope(Organizations.contextOf(this)).where(({ shipments }) => shipments.organization_id["="](this.id)).cardinality("many"); }
@expose() users() { return Users.scope(Organizations.contextOf(this)).where(({ users }) => users.organization_id["="](this.id)).cardinality("many"); }
@expose() customers() { return Relation.has(this, Customers, { organization_id: this.id }); }
@expose() inventory_positions() { return Relation.has(this, InventoryPositions, { organization_id: this.id }); }
@expose() locations() { return Relation.has(this, Locations, { organization_id: this.id }); }
@expose() orders() { return Relation.has(this, Orders, { organization_id: this.id }); }
@expose() shipments() { return Relation.has(this, Shipments, { organization_id: this.id }); }
@expose() users() { return Relation.has(this, Users, { organization_id: this.id }); }
// @generated-end
}
20 changes: 10 additions & 10 deletions site/src/demo/schema/shipments.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { sql, expose } from "typegres";
import { Relation, sql, expose } from "typegres";
import { Int8, Text, Timestamptz } from "typegres/postgres";
import { db } from "../runtime";
import { Orders } from "./orders";
import { Organizations } from "./organizations";
export class Shipments extends db.Table("shipments", { live: true }) {
// @generated-start
@expose() id = (Int8<1>).column({ nonNull: true, generated: true });
@expose() organization_id = (Int8<1>).column({ nonNull: true });
@expose() order_id = (Int8<1>).column({ nonNull: true });
@expose() carrier = (Text<1>).column({ nonNull: true });
@expose() cutoff_at = (Timestamptz<1>).column({ nonNull: true });
@expose() shipped_at = (Timestamptz<0 | 1>).column();
@expose() status = (Text<1>).column({ nonNull: true, default: sql`'pending'::text` });
@expose() id = Int8.column({ nonNull: true, generated: true });
@expose() organization_id = Int8.column({ nonNull: true });
@expose() order_id = Int8.column({ nonNull: true });
@expose() carrier = Text.column({ nonNull: true });
@expose() cutoff_at = Timestamptz.column({ nonNull: true });
@expose() shipped_at = Timestamptz.column();
@expose() status = Text.column({ nonNull: true, default: sql`'pending'::text` });
// relations
@expose() order() { return Orders.scope(Shipments.contextOf(this)).where(({ orders }) => orders.id["="](this.order_id)).cardinality("one"); }
@expose() organization() { return Organizations.scope(Shipments.contextOf(this)).where(({ organizations }) => organizations.id["="](this.organization_id)).cardinality("one"); }
@expose() order() { return Relation.belongsTo(this, Orders, { id: this.order_id }); }
@expose() organization() { return Relation.belongsTo(this, Organizations, { id: this.organization_id }); }
// @generated-end
}
16 changes: 8 additions & 8 deletions site/src/demo/schema/users.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { expose } from "typegres";
import { Relation, expose } from "typegres";
import { Int8, Text } from "typegres/postgres";
import { db } from "../runtime";
import { Organizations } from "./organizations";
export class Users extends db.Table("users", { live: true }) {
// @generated-start
@expose() id = (Int8<1>).column({ nonNull: true, generated: true });
@expose() organization_id = (Int8<1>).column({ nonNull: true });
@expose() name = (Text<1>).column({ nonNull: true });
@expose() email = (Text<1>).column({ nonNull: true });
@expose() role = (Text<1>).column({ nonNull: true });
@expose() token = (Text<1>).column({ nonNull: true });
@expose() id = Int8.column({ nonNull: true, generated: true });
@expose() organization_id = Int8.column({ nonNull: true });
@expose() name = Text.column({ nonNull: true });
@expose() email = Text.column({ nonNull: true });
@expose() role = Text.column({ nonNull: true });
@expose() token = Text.column({ nonNull: true });
// relations
@expose() organization() { return Organizations.scope(Users.contextOf(this)).where(({ organizations }) => organizations.id["="](this.organization_id)).cardinality("one"); }
@expose() organization() { return Relation.belongsTo(this, Organizations, { id: this.organization_id }); }
// @generated-end
}
Loading