Melon-dbMelon-db
Sync

Supported data types

Melon-db scalar types, storage mapping, and sync serialization.

Melon-db schemas use a fixed set of scalar kinds. Adapters map them to SQLite column types; sync sends JSON-compatible payloads.

Scalar kinds (MelonScalar)

KindTypeScript (app)SQLite (typical)Sync over JSON
stringstringTEXTstring
numbernumberREAL / INTEGERnumber
booleanbooleanINTEGER (0/1)boolean
dateDateINTEGER (ms) or TEXT (ISO)ISO string recommended
jsonobject / arrayTEXT (serialized)object / array
bytesUint8ArrayBLOBbase64 or binary transport-specific

Define fields in schema:

fields: {
  id: { kind: 'string' },
  count: { kind: 'number' },
  active: { kind: 'boolean' },
  updatedAt: { kind: 'date' },
  metadata: { kind: 'json', nullable: true },
  thumbnail: { kind: 'bytes', nullable: true },
}

Nullability

nullable: true allows null in storage. Required fields should omit nullable or set nullable: false.

Indexes

  • Per-field indexed: true for single-column hints.
  • Composite indexes via indexes: [['status', 'updatedAt']].

Indexes affect query performance only — they do not change the TypeScript kind.

Query operators by type

OperatorsWorks on
eq, neq, in, notInall scalars
gt, gte, lt, ltenumber, date
like, containsstring (and contains on json string fields in limited cases)
isNullany nullable field

Relations are not a type

Foreign keys are stored as ordinary fields (projectId: { kind: 'string' }). Relation metadata drives include and validation only.

Sync payload notes

  • Dates: serialize as ISO 8601 strings in created / updated arrays unless you standardize on numeric epochs both sides.
  • JSON: must be JSON-serializable — no Date, Map, or undefined inside json fields on the wire.
  • Bytes: prefer base64 in JSON APIs; adapters may store raw BLOB locally.
  • Deletes: push/pull use string primary keys in the deleted array.

Unsupported / deferred

FeatureStatus
Auto-increment integer idsuse string ids or assign in app code
Enums as first-class schema kinduse string + app-level constants
Full-text searchuse like or raw SQL migrations
Partial / filtered indexesdeclare via sql migration step
  • Schema — field definitions
  • Backend — wire format for SyncChanges
  • FAQ — common type mistakes