# Schema helpers

Zod validation and inferred database types.

[Read the schemas and types guide](/docs/schemas/). Signatures below come from the published SDK declarations. Access SDK services through `db`; use their constructors only when integrating at a lower level.

## zodTable


```ts
/** Pass a Zod schema to validate both writes and incoming records. Transforms are not applied. */
declare function zodTable<T extends object>(
  schema: ZodType<T>,
  options?: Omit<TableDefinition<T>, "validate">,
): TableDefinition<T>;
```

## defineTable


```ts
declare function defineTable<T extends object>(
  definition: TableDefinition<T>,
): TableDefinition<T>;
```

## defineSchema


```ts
declare function defineSchema<DB extends SchemaShape<DB>>(schema: {
  [K in keyof DB]: TableDefinition<DB[K]>;
}): {
  [K in keyof DB]: TableDefinition<DB[K]>;
};
```

## InferDatabase


```ts
type InferDatabase<S> = {
  [K in keyof S]: S[K] extends TableDefinition<infer T> ? T : never;
};
```
