@atscript/utils-db 0.1.30 → 0.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -245,9 +245,29 @@ These `@db.*` annotations are defined in `@atscript/core` and processed by `Atsc
245
245
  | `@db.index.plain "name"` | Field | B-tree index (optional sort: `"name", "desc"`) |
246
246
  | `@db.index.unique "name"` | Field | Unique index |
247
247
  | `@db.index.fulltext "name"` | Field | Full-text search index |
248
+ | `@db.json` | Field | Store as a single JSON column (skip flattening) |
248
249
 
249
250
  Multiple fields with the same index name form a **composite index**.
250
251
 
252
+ ## Type-Safe Queries with `__flat`
253
+
254
+ Interfaces annotated with `@db.table` get a `__flat` static property in the generated `.d.ts` file, mapping all dot-notation paths to their value types. This enables autocomplete and type checking for filter expressions and `$select`/`$sort` operations.
255
+
256
+ Use `FlatOf<T>` to extract the flat type:
257
+
258
+ ```typescript
259
+ import type { FlatOf } from '@atscript/utils-db'
260
+
261
+ type UserFlat = FlatOf<typeof User>
262
+ // → { id: number; name: string; contact: never; "contact.email": string; ... }
263
+ ```
264
+
265
+ `AtscriptDbTable` uses `FlatOf<T>` as the type parameter for query methods (`findOne`, `findMany`, `count`, `updateMany`, `replaceMany`, `deleteMany`), giving you autocomplete on filter keys and select paths. When `__flat` is not present (no `@db.table`), `FlatOf<T>` falls back to the regular data shape — fully backward-compatible.
266
+
267
+ ### `$select` Parent Path Expansion
268
+
269
+ Selecting a parent object path (e.g., `$select: ['contact']`) automatically expands to all its leaf physical columns for relational databases. Sorting by parent paths is silently ignored.
270
+
251
271
  ## Cross-Cutting Concerns
252
272
 
253
273
  Since `AtscriptDbTable` is concrete, extend it for cross-cutting concerns that work with any adapter:
@@ -305,6 +325,7 @@ export { decomposePatch } from './patch-decomposer'
305
325
  export { getKeyProps } from './patch-types'
306
326
 
307
327
  // Types
328
+ export type { FlatOf } from '@atscript/typescript/utils'
308
329
  export type {
309
330
  TDbFilter, TDbFindOptions,
310
331
  TDbInsertResult, TDbInsertManyResult, TDbUpdateResult, TDbDeleteResult,