Releases: DWTechs/Antity-pgsql.js
Releases · DWTechs/Antity-pgsql.js
Single `consumer` object
- Replace separate
consumerId/consumerNameparameters with a singleconsumerobject ({ id?, nickname? }) across all relevant APIs:query.update(),query.insert(),query.upsert(),query.archive()now acceptconsumer?: { id?: number | string, nickname?: string }instead of two separate arguments- Express middlewares (
add,update,upsert,archive,sync) now readres.locals.consumer.idandres.locals.consumer.nicknameinstead ofres.locals.consumerId/res.locals.consumerName
Fix 'in' 'notin'
- Fix
notInmatch mode not working in filter SQL generation: - Add
"in"and"notIn"to allowed match modes fornumberandstring
Fix filters empty values
- Fix filter handling to exclude empty values from WHERE clauses:
- Filters with empty string values are now skipped
- Filters with empty arrays are now skipped
- Filters with null values are skipped except for
isandisNotmatch modes
Sync
- Add bulk sync functionality:
- New
sync()Express middleware atomically synchronises a table with the full provided row list inside a single PostgreSQL transaction (BEGIN / COMMIT / ROLLBACK on failure) - Incoming rows without an ID (or with an unknown ID) are inserted; rows with a known ID are updated; existing rows absent from the list are deleted
- Accepts optional
idFieldin request body (defaults to'id') to specify the identity column - Accepts optional
filtersin request body to scope the managed set — rows outside the filter are never touched - Returns synced rows with generated IDs in
res.locals.rows - Returns operation summary
{ inserted, updated, deleted }inres.locals.sync - Supports
consumerId/consumerNameforwarding for history tracking on inserts and updates
- New
- Add
syncArraySubstackgetter returning[normalizeArray, validateArray, sync]middleware chain
UPSERT
- Add UPSERT functionality using PostgreSQL's
INSERT ... ON CONFLICT ... DO UPDATEsyntax:- New
query.upsert()method generates upsert queries with configurable conflict targets - Supports single or multiple column conflict targets (e.g.,
'id'or['email', 'username']) - Properties with both
INSERTandUPDATEoperations are automatically included in upsert - Optionally includes
consumerIdandconsumerNamefor history tracking - Supports
RETURNINGclause to retrieve updated/inserted row IDs
- New
- Add
upsert()Express middleware for handling upsert operations:- Expects
rowsandconflictTargetin request body - Returns upserted rows with IDs in
res.locals.rows - Supports chunking for bulk operations
- Expects
- Add convenience Express substack middlewares:
upsertArraySubstack: Returns[normalizeArray, validateArray, upsert]middleware chainupsertOneSubstack: Returns[normalizeOne, validateOne, upsert]middleware chain
Add dedicated `Archive` query
- Add dedicated
Archivequery :- Replaces the previous approach of passing
archived: truethrough the genericUpdatequery - Generates a simplified
UPDATE ... SET archived = true WHERE id IN (...)query directly - Optionally appends
consumerIdandconsumerNameas single scalar values (not per-row CASE blocks)
- Replaces the previous approach of passing
- Add
query.archive()method toSQLEntityusing the newArchiveclass - Add
propertiesgetter toSQLEntityreturning the list ofPropertyinstances passed at construction
`update` middleware forwards rows to `res.locals.rows`
updatemiddleware now forwards sanitized and normalized rows tores.locals.rowsfor use in subsequent middlewares and response handling. Likeaddandgetmiddlewares
Fix wildcard placement in LIKE queries
- Fix wildcard placement in LIKE queries:
- Wildcards (%) are now added to string values instead of SQL parameter placeholders
- Affects matchModes:
startsWith,endsWith,contains,notContains - SQL now generates
LIKE $1with value'%abc%'instead ofLIKE %$1%with value'abc'
Array based filters
- Add support for array-based filter format with multiple filters per property:
- Filters now accept both simple format (single object) and complex format (array of objects)
- Simple format:
{name: {value: "John", matchMode: "contains"}}(backward compatible) - Complex format:
{name: [{value: "John", matchMode: "contains", operator: "or"}]}(new) - Support logical operators (AND/OR) to combine multiple filters on the same property
- Example:
{name: [{value: "John", operator: "or"}, {value: "Jane", operator: "or"}]}
- Fix
isFilterableproperty in declaration file
isFilterable and other new property names
- Rename Property interface properties for better clarity and consistency:
typeCheck→isTypeChecked: Boolean flag to enable/disable type checkingfilter→isFilterable: Boolean flag to enable/disable filtering in SELECT operationsneed→requiredFor: Array of REST methods (POST, PUT, PATCH) that require this propertysend→isPrivate: Boolean flag inverted -send: truebecomesisPrivate: false
- Rename entity getter method:
unsafeProps→privateProps: Returns array of property names that are private
- Update dependencies:
- "@dwtechs/antity": "0.16.0"