Skip to content

serializeMessage

serializeMessage<Desc>(schema, message, columnMap?, columns?): Record<string, unknown>

Defined in: serialization.ts:60

Convert a protobuf message into a plain object suitable for database insertion. Uses @bufbuild/protobuf’s toJson for type-safe serialization (bigints as strings, Timestamps as RFC 3339, etc.), then remaps keys via the optional columnMap.

When a columns config is provided:

  • Fields with ignore: true are excluded from the output.
  • Fields with serialize: "json" are stored as JSON strings via toJsonString.
  • Fields with serialize: "binary" are stored as Uint8Array via toBinary.
  • Fields with name overrides use the specified database column name.

Desc extends DescMessage

Desc

The message descriptor.

MessageShape<Desc>

The message to serialize.

Record<string, string>

Map of proto field names (snake_case) to database column names.

Record<string, ColumnConfig>

Per-field column configuration.

Record<string, unknown>