Skip to content

Commit a3b2006

Browse files
committed
Sorting for TypeIdentifier
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
1 parent 3d471f8 commit a3b2006

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/postgres/src/storage.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,13 @@ abstract class PostgresAdapterBase implements DbAdapter {
991991
const key = escape(_key)
992992
if (attr !== undefined && NumericTypes.includes(attr.type._class)) {
993993
res.push(`(${this.getKey(_class, baseDomain, key, joins)})::numeric ${val === 1 ? 'ASC' : 'DESC'}`)
994+
} else if (attr !== undefined && attr.type._class === core.class.TypeIdentifier) {
995+
res.push(
996+
`regexp_replace(COALESCE(${this.getKey(_class, baseDomain, key, joins)}, ''), '-?\\d+$', '') ${val === 1 ? 'ASC' : 'DESC'}`
997+
)
998+
res.push(
999+
`COALESCE(NULLIF(regexp_replace(${this.getKey(_class, baseDomain, key, joins)}, '.*?(\\d+)$', '\\1'), ''), '0')::INT ${val === 1 ? 'ASC' : 'DESC'}`
1000+
)
9941001
} else {
9951002
res.push(`${this.getKey(_class, baseDomain, key, joins)} ${val === 1 ? 'ASC' : 'DESC'}`)
9961003
}

0 commit comments

Comments
 (0)