This page reflects the exported types in the supplied repository snapshot. ## Entry point ```ts compile(db, request, user, role, structure, options?): Promise ``` | Parameter | Type | Meaning | |---|---|---| | `db` | `Database \| Transaction` | Supported Drizzle database or transaction | | `request` | `Request` | Single structured query or phase collection | | `user` | `any` | Application-provided session context | | `role` | `string` | Role key used to select permissions | | `structure` | `Structure` | Table, endpoint, and policy map | | `options` | `BuildWhereOptions` | Currently includes `disable_triggers?` | ## Structure ```ts type Structure = Record; type TableStructure = { endpoints: Endpoint[]; table: any; }; ``` ## Endpoint ```ts type EndpointType = "GET" | "PUT" | "POST" | "DELETE"; type Endpoint = { type: EndpointType; triggers?: TriggerStructure[]; [role: string]: RolePermissions | typeof NONE | any; }; ``` ## Role permissions ```ts type RolePermissions = { allowed: FieldPermission; // alias: allow disallowed?: FieldPermission; // alias: deny limit?: number; order_by?: string[] | string; group_by?: string[] | string; returning?: /* field permission object */; }; ``` ```ts type FieldPermission = | string | string[] | { field: string | string[]; where?: WhereCondition }; ``` Presets: ```ts ALL = { allowed: ["*"], disallowed: [] } ALL_EXCEPT_ID = { allowed: ["*"], disallowed: ["id"] } NONE = { allowed: [], disallowed: [] } ``` ## Request ```ts type Request = StructuredQuery | { phases: QueryPhase[] }; type StructuredQuery = { table: keyof Structure; type: EndpointType; select?: string[] | string; join?: Join[]; where?: WhereCondition; data?: Record | Record[]; group_by?: string[] | string; order_by?: string[] | string; returning?: string[] | string; limit?: number; }; ``` ## Join ```ts type Join = { table: keyof Structure; type: "INNER" | "LEFT"; on: Record | WhereCondition; }; ``` ## Nested conditions ```ts { and: [condition, condition] } { or: [condition, condition] } { not: condition } { if: { when: condition, do: condition | boolean, else: condition | boolean } } ``` `do` and `else` also accept structured queries or functions in the exported type, but function and structured-query actions are rejected when used as a SQL `where` condition. Treat action context carefully. ## Query phases ```ts type QueryPhase = { mode: "TRANSACTION" | "QUERY"; queries: StructuredQuery[]; }; ``` See [Operators](Operators), [Errors and Results](Errors-and-Results), and [Triggers and Extensibility](Triggers-and-Extensibility). [← Recipes](Recipes) · [Operators →](Operators)