const std = @import("std"); const pgmql = @import("pgmql"); const _example = @import("../example.zig"); pub const CreateDispatcher = _example.builder.dispatchers.Dispatcher(struct {}); pub const InvoiceModel = pgmql.Model{ .table = "invoices", .primaryKey = .{ .single = "id" }, .definition = struct { pub const id = pgmql.types.Serial{}; pub const createdAt = pgmql.types.DateTime{}; pub const amount = pgmql.types.Decimal{ .column = .{ .type = "MONEY", }, }; pub const products = pgmql.relationships.Models{ .related = "InvoiceProduct", .relationship = .{ .direct = .{ .foreignKey = "invoiceId", }, }, }; }, // .crudPolicy = _example.builder.policies.crud(.{ .any = false }), // // .dispatchers = struct { // pub const create = CreateDispatcher{ // .policy = .{ // .func = struct { pub fn f(context: CreateDispatcher.PolicyContext) bool { // if (context.account) |account| { // return std.mem.eql(u8, "billing", account.role) or std.mem.eql(u8, "admin", account.role); // } else { // return false; // } // } }.f // }, // .run = struct { pub fn f(context: CreateDispatcher.Context) void { // _ = context; // // const invoice = _example.registry.models.Invoice.initStruct(); // _ = invoice; // } }.f, // }; // }, }; pub const Invoice = InvoiceModel.structure();