SERVER / DATABASE / ENTITIES

Entities

An entity is an importable server contract that names a table, its fields, and the constraints Dowe can lower into deterministic PostgreSQL or D1 migrations. Dowe Database remains schema-less and does not create a local SQL schema from entities.

1 / DECLARATION

Describe one table with explicit fields

The declaration name is a server binding. Dowe converts it to a lower-snake-case table name, so SmsDeliveries targets sms_deliveries. Every entity must declare at least one field and may declare at most one primary field.

dowe
entity SmsDeliveries
  id:string primary:true
  recipient:string required:true index:true
  providerMessageId:string unique:true
  status:string required:true index:true
  attempts:int required:true
  cost:decimal
  createdAt:timestamp required:true index:true
  metadata:json
When no field is marked primary and an id field exists, Dowe promotes that id field to required primary. It does not add a missing id field to an entity.

2 / FIELD TYPES

Use the implemented portable type set

Entity field types are fixed and validated during compilation. The provider migration maps each type to its current SQL representation.

Dowe type
Provider mapping

No data

There are no records to display

3 / CONSTRAINTS

Make storage requirements visible

Constraint props are boolean and belong after the field type. Unknown props, duplicate fields, unsupported types, and multiple primary fields fail compilation.

Constraint
Generated behavior

No data

There are no records to display

Entities do not currently declare foreign keys, relations, defaults, compound indexes, or provider-specific column types.

4 / MODULES AND DATABASE CONFIG

Group a bounded domain behind one module

Keep related declarations together under server/entities and import their named bindings into a shared Database config module. Prefer one focused plural file per bounded domain instead of one file per table. Keep isolated schemas separate and split modules when ownership, lifecycle, authorization, or size demands it.

server/entities/sms-entities.dowe

dowe
entity SmsDeliveries
  id:string primary:true
  recipient:string required:true index:true
  status:string required:true index:true
  createdAt:timestamp required:true

entity SmsDeliveryEvents
  id:string primary:true
  deliveryId:string required:true index:true
  status:string required:true index:true
  createdAt:timestamp required:true

server/config/database.dowe

dowe
import SmsDeliveries, SmsDeliveryEvents from "@/server/entities/sms-entities"

database appDb provider:"postgres"
  host:env.POSTGRES_HOST
  port:env.POSTGRES_PORT
  account:env.POSTGRES_USER
  secret:env.POSTGRES_PASSWORD
  name:env.POSTGRES_DATABASE
  entities:[SmsDeliveries SmsDeliveryEvents]
  seeders:[]

5 / PROVIDER BEHAVIOR

Know what the entity controls

Provider
Entity effect

No data

There are no records to display

A query still uses conn:<handle>.<operation> and a table string. An entity is compile-time schema and migration authority for SQL providers, not a runtime Database handle and not a value exposed to Views.

Migration graph