Skip to content

Comments

Add support for Postgres arrays mapped to JSON#41

Merged
elledienne merged 3 commits intomainfrom
feat/postgres-array-support
Jun 29, 2025
Merged

Add support for Postgres arrays mapped to JSON#41
elledienne merged 3 commits intomainfrom
feat/postgres-array-support

Conversation

@elledienne
Copy link
Contributor

@elledienne elledienne commented Jun 29, 2025

Summary

  • Add support for Postgres arrays (string[], int[], etc.) by mapping them to JSON
  • Remove filter that previously excluded array fields from schema generation
  • Map array types to json<type[]>() syntax for proper TypeScript type safety

Example

model User {
  id    String   @id
  tags  String[] // Maps to json<string[]>()
  scores Int[]?  // Maps to json<number[]>().optional()
  roles UserRole[] // Maps to json<UserRole[]>()
}

Lorenzo De Nobili and others added 3 commits June 29, 2025 20:26
Zero doesn't natively support Postgres arrays, but they can be stored as JSON.
This change extends the generator to detect array fields (string[], int[], etc.)
and map them to json<type[]>() in the Zero schema while preserving TypeScript
type safety.

Changes:
- Remove filter that excluded array fields from schema generation
- Map array types to json<T[]>() in typeMapper (e.g., json<string[]>())
- Support all Prisma array types: String[], Int[], Float[], Boolean[], DateTime[], etc.
- Support enum arrays: MyEnum[]
- Handle optional arrays and database column mapping
- Add comprehensive test coverage for array support

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add new section explaining how arrays are mapped to JSON
- Include examples of Prisma schema with arrays and generated Zero schema
- Document all supported array types (scalar, enum, optional)
- Remove outdated note about array exclusion
- Update package description to mention array support

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@elledienne elledienne merged commit 5db79e7 into main Jun 29, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant