Skip to content

feat(core): support array option on scalar properties#7378

Merged
B4nan merged 1 commit intonextfrom
feat/array-option-for-scalars
Apr 18, 2026
Merged

feat(core): support array option on scalar properties#7378
B4nan merged 1 commit intonextfrom
feat/array-option-for-scalars

Conversation

@B4nan
Copy link
Copy Markdown
Member

@B4nan B4nan commented Mar 22, 2026

Summary

  • Expose array: true on PropertyOptions so scalar properties can use it via @Property({ type: IntegerType, array: true }) or p.integer().array()
  • During discovery, when array: true is set on a scalar with a custom type, the type is automatically wrapped in an ArrayType that delegates element conversion to the inner type's convertToJSValue/convertToDatabaseValue
  • Column type is inferred as innerType.getColumnType() + '[]' (e.g. int[], text[], numeric(10,2)[])

Relates to #7363 — provides a simpler alternative without introducing a new type class.

Usage

// defineEntity
integers: p.integer().array()
decimals: p.decimal('number').array().precision(10).scale(2)
custom:   p.type(new PlainTimeType()).array()

// decorators
@Property({ type: IntegerType, array: true })
integers!: number[];

🤖 Generated with Claude Code

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.64%. Comparing base (8808779) to head (02899d3).
⚠️ Report is 22 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff            @@
##             next    #7378    +/-   ##
========================================
  Coverage   99.64%   99.64%            
========================================
  Files         262      262            
  Lines       26080    26105    +25     
  Branches     7207     7061   -146     
========================================
+ Hits        25987    26012    +25     
  Misses         88       88            
  Partials        5        5            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread packages/core/src/metadata/MetadataDiscovery.ts Outdated
@B4nan B4nan force-pushed the feat/array-option-for-scalars branch from 565981c to 3b9b30a Compare March 22, 2026 16:00
@B4nan B4nan marked this pull request as ready for review March 22, 2026 16:02
@B4nan B4nan force-pushed the feat/array-option-for-scalars branch 2 times, most recently from b2b2968 to e29a8f1 Compare March 22, 2026 16:10
@DASPRiD
Copy link
Copy Markdown
Contributor

DASPRiD commented Mar 22, 2026

LGTM, definitely better than my implementation, I agree. I also like that this additionally supports other database engines this way. Good job! 👍

@vaskouk
Copy link
Copy Markdown
Contributor

vaskouk commented Mar 22, 2026

Whats the diff than having prices: p.array(Number) ?

@B4nan
Copy link
Copy Markdown
Member Author

B4nan commented Mar 22, 2026

p.array(Number) stores in text[] I think? With p.integer().array() you get int[].

@vaskouk
Copy link
Copy Markdown
Contributor

vaskouk commented Mar 22, 2026

p.array(Number) stores in text[] I think? With p.integer().array() you get int[].

True true. Now i see, nice improvement!

@vaskouk
Copy link
Copy Markdown
Contributor

vaskouk commented Mar 22, 2026

For custom types, it requires to define it like this:p.type(new DecimalJsType).array() or can also stay as p.type(DecimalJsType).array() ?

@B4nan
Copy link
Copy Markdown
Member Author

B4nan commented Mar 22, 2026

Both should work, will adjust some tests to use that approach too.

@B4nan B4nan force-pushed the feat/array-option-for-scalars branch 2 times, most recently from 64de58d to 025767f Compare April 1, 2026 14:53
Allow `p.integer().array()`, `p.type(new CustomType()).array()`, and
`@Property({ type: IntegerType, array: true })` for scalar properties.

During discovery, when `array: true` is set on a scalar with a custom
type, the type is automatically wrapped in an `ArrayType` that delegates
element conversion to the inner type. The column type is inferred as
`innerType.getColumnType() + '[]'` on platforms with native array
support (postgres), or falls back to the platform's default array
storage type (e.g. `text`) on others.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@B4nan B4nan force-pushed the feat/array-option-for-scalars branch from 025767f to 02899d3 Compare April 14, 2026 07:22
@B4nan B4nan changed the base branch from master to next April 18, 2026 14:29
@B4nan B4nan merged commit b520b37 into next Apr 18, 2026
22 checks passed
@B4nan B4nan deleted the feat/array-option-for-scalars branch April 18, 2026 14:44
@vkouk
Copy link
Copy Markdown
Contributor

vkouk commented Apr 18, 2026

Both should work, will adjust some tests to use that approach too.

@B4nan does it work the way I posted above ? Did you figure out or shall we test and see ?

@B4nan
Copy link
Copy Markdown
Member Author

B4nan commented Apr 18, 2026

I dont remember, give it a try :)

B4nan added a commit that referenced this pull request Apr 19, 2026
## Summary

- Expose `array: true` on `PropertyOptions` so scalar properties can use
it via `@Property({ type: IntegerType, array: true })` or
`p.integer().array()`
- During discovery, when `array: true` is set on a scalar with a custom
type, the type is automatically wrapped in an `ArrayType` that delegates
element conversion to the inner type's
`convertToJSValue`/`convertToDatabaseValue`
- Column type is inferred as `innerType.getColumnType() + '[]'` (e.g.
`int[]`, `text[]`, `numeric(10,2)[]`)

Relates to #7363 — provides a simpler alternative without introducing a
new type class.

### Usage

```ts
// defineEntity
integers: p.integer().array()
decimals: p.decimal('number').array().precision(10).scale(2)
custom:   p.type(new PlainTimeType()).array()

// decorators
@Property({ type: IntegerType, array: true })
integers!: number[];
```


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

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
B4nan added a commit that referenced this pull request Apr 20, 2026
## Summary

- Expose `array: true` on `PropertyOptions` so scalar properties can use
it via `@Property({ type: IntegerType, array: true })` or
`p.integer().array()`
- During discovery, when `array: true` is set on a scalar with a custom
type, the type is automatically wrapped in an `ArrayType` that delegates
element conversion to the inner type's
`convertToJSValue`/`convertToDatabaseValue`
- Column type is inferred as `innerType.getColumnType() + '[]'` (e.g.
`int[]`, `text[]`, `numeric(10,2)[]`)

Relates to #7363 — provides a simpler alternative without introducing a
new type class.

### Usage

```ts
// defineEntity
integers: p.integer().array()
decimals: p.decimal('number').array().precision(10).scale(2)
custom:   p.type(new PlainTimeType()).array()

// decorators
@Property({ type: IntegerType, array: true })
integers!: number[];
```


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

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants