feat(core): support array option on scalar properties#7378
Conversation
cd5ec69 to
565981c
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
565981c to
3b9b30a
Compare
b2b2968 to
e29a8f1
Compare
|
LGTM, definitely better than my implementation, I agree. I also like that this additionally supports other database engines this way. Good job! 👍 |
|
Whats the diff than having |
|
|
True true. Now i see, nice improvement! |
|
For custom types, it requires to define it like this: |
|
Both should work, will adjust some tests to use that approach too. |
64de58d to
025767f
Compare
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>
025767f to
02899d3
Compare
@B4nan does it work the way I posted above ? Did you figure out or shall we test and see ? |
|
I dont remember, give it a try :) |
## 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>
## 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>
Summary
array: trueonPropertyOptionsso scalar properties can use it via@Property({ type: IntegerType, array: true })orp.integer().array()array: trueis set on a scalar with a custom type, the type is automatically wrapped in anArrayTypethat delegates element conversion to the inner type'sconvertToJSValue/convertToDatabaseValueinnerType.getColumnType() + '[]'(e.g.int[],text[],numeric(10,2)[])Relates to #7363 — provides a simpler alternative without introducing a new type class.
Usage
🤖 Generated with Claude Code