@platformatic/sql-mapper 3.53.0-alpha.0 → 3.54.0
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/index.js +0 -12
- package/lib/entity.js +2 -16
- package/lib/queries/pg.js +4 -15
- package/package.json +3 -3
- package/lib/vector.js +0 -34
package/index.js
CHANGED
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
import * as queriesFactory from './lib/queries/index.js'
|
|
14
14
|
import { setupTelemetry } from './lib/telemetry.js'
|
|
15
15
|
import { areSchemasSupported } from './lib/utils.js'
|
|
16
|
-
import { parseVector } from './lib/vector.js'
|
|
17
16
|
|
|
18
17
|
// Ignore the function as it is only used only for MySQL and PostgreSQL
|
|
19
18
|
/* istanbul ignore next */
|
|
@@ -77,16 +76,6 @@ const defaultAutoTimestampFields = {
|
|
|
77
76
|
updatedAt: 'updated_at'
|
|
78
77
|
}
|
|
79
78
|
|
|
80
|
-
async function registerPostgreSQLExtensionTypes (db) {
|
|
81
|
-
try {
|
|
82
|
-
await db.registerTypeParser('vector', parseVector)
|
|
83
|
-
} catch {}
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
await db.registerTypeParser('_vector', value => db.parseArray(value, parseVector))
|
|
87
|
-
} catch {}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
79
|
export async function createConnectionPool ({
|
|
91
80
|
log,
|
|
92
81
|
connectionString,
|
|
@@ -113,7 +102,6 @@ export async function createConnectionPool ({
|
|
|
113
102
|
queueTimeoutMilliseconds,
|
|
114
103
|
acquireLockTimeoutMilliseconds
|
|
115
104
|
)
|
|
116
|
-
await registerPostgreSQLExtensionTypes(db)
|
|
117
105
|
sql = createConnectionPoolPg.sql
|
|
118
106
|
db.isPg = true
|
|
119
107
|
} else if (connectionString.indexOf('mysql') === 0) {
|
package/lib/entity.js
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
} from './errors.js'
|
|
15
15
|
import { wrapDB } from './telemetry.js'
|
|
16
16
|
import { sanitizeLimit, tableName, toLowerFirst, toSingular, toUpperFirst } from './utils.js'
|
|
17
|
-
import { isVectorType, parseVector, serializeVector } from './vector.js'
|
|
18
17
|
|
|
19
18
|
function createMapper (
|
|
20
19
|
defaultDb,
|
|
@@ -76,7 +75,7 @@ function createMapper (
|
|
|
76
75
|
function fixInput (input) {
|
|
77
76
|
const newInput = {}
|
|
78
77
|
for (const key of Object.keys(input)) {
|
|
79
|
-
|
|
78
|
+
const value = input[key]
|
|
80
79
|
let newKey = inputToFieldMap[key]
|
|
81
80
|
if (newKey === undefined) {
|
|
82
81
|
if (fields[key] !== undefined) {
|
|
@@ -85,11 +84,6 @@ function createMapper (
|
|
|
85
84
|
throw new UnknownFieldError(key)
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
|
-
|
|
89
|
-
if (isVectorType(fields[newKey].sqlType)) {
|
|
90
|
-
value = serializeVector(value)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
87
|
newInput[newKey] = value
|
|
94
88
|
}
|
|
95
89
|
return newInput
|
|
@@ -106,9 +100,6 @@ function createMapper (
|
|
|
106
100
|
if (primaryKeys.has(key) && value !== null && value !== undefined) {
|
|
107
101
|
value = value.toString()
|
|
108
102
|
}
|
|
109
|
-
if (newKey && isVectorType(fields[key].sqlType)) {
|
|
110
|
-
value = parseVector(value)
|
|
111
|
-
}
|
|
112
103
|
newOutput[newKey] = value
|
|
113
104
|
}
|
|
114
105
|
return newOutput
|
|
@@ -336,10 +327,6 @@ function createMapper (
|
|
|
336
327
|
}
|
|
337
328
|
|
|
338
329
|
function computeCriteriaValue (fieldWrap, value) {
|
|
339
|
-
if (isVectorType(fieldWrap.sqlType)) {
|
|
340
|
-
return sql`${serializeVector(value)}`
|
|
341
|
-
}
|
|
342
|
-
|
|
343
330
|
if (Array.isArray(value)) {
|
|
344
331
|
return sql`(${sql.join(
|
|
345
332
|
value.map(v => computeCriteriaValue(fieldWrap, v)),
|
|
@@ -500,8 +487,7 @@ export function buildEntity (
|
|
|
500
487
|
acc[column.column_name] = {
|
|
501
488
|
sqlType: column.udt_name,
|
|
502
489
|
isNullable: column.is_nullable === 'YES',
|
|
503
|
-
isArray: column.isArray
|
|
504
|
-
vectorDimensions: column.vectorDimensions
|
|
490
|
+
isArray: column.isArray
|
|
505
491
|
}
|
|
506
492
|
|
|
507
493
|
// To get enum values in mysql and mariadb
|
package/lib/queries/pg.js
CHANGED
|
@@ -46,16 +46,10 @@ export async function listColumns (db, sql, table, schema) {
|
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
48
|
const res = await db.query(sql`
|
|
49
|
-
SELECT
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
JOIN pg_catalog.pg_namespace ns ON ns.oid = cls.relnamespace AND ns.nspname = c.table_schema
|
|
54
|
-
JOIN pg_catalog.pg_attribute a ON a.attrelid = cls.oid AND a.attname = c.column_name
|
|
55
|
-
WHERE c.table_name = ${table}
|
|
56
|
-
AND c.table_schema = ${schema}
|
|
57
|
-
AND a.attnum > 0
|
|
58
|
-
AND NOT a.attisdropped
|
|
49
|
+
SELECT column_name, udt_name, is_nullable, is_generated, data_type
|
|
50
|
+
FROM information_schema.columns
|
|
51
|
+
WHERE table_name = ${table}
|
|
52
|
+
AND table_schema = ${schema}
|
|
59
53
|
`)
|
|
60
54
|
|
|
61
55
|
for (const col of res) {
|
|
@@ -65,11 +59,6 @@ export async function listColumns (db, sql, table, schema) {
|
|
|
65
59
|
} else {
|
|
66
60
|
col.isArray = false
|
|
67
61
|
}
|
|
68
|
-
|
|
69
|
-
const match = col.formatted_type?.match(/^vector\((\d+)\)$/)
|
|
70
|
-
if (match) {
|
|
71
|
-
col.vectorDimensions = Number(match[1])
|
|
72
|
-
}
|
|
73
62
|
}
|
|
74
63
|
|
|
75
64
|
return res
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/sql-mapper",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.54.0",
|
|
4
4
|
"description": "A data mapper utility for SQL databases",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"camelcase": "^6.3.0",
|
|
36
36
|
"fastify-plugin": "^5.0.0",
|
|
37
37
|
"inflected": "^2.1.0",
|
|
38
|
-
"@platformatic/foundation": "3.
|
|
39
|
-
"@platformatic/telemetry": "3.
|
|
38
|
+
"@platformatic/foundation": "3.54.0",
|
|
39
|
+
"@platformatic/telemetry": "3.54.0"
|
|
40
40
|
},
|
|
41
41
|
"tsd": {
|
|
42
42
|
"directory": "test/types"
|
package/lib/vector.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export function isVectorType (sqlType) {
|
|
2
|
-
return sqlType === 'vector'
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function serializeVector (value) {
|
|
6
|
-
if (Array.isArray(value)) {
|
|
7
|
-
return JSON.stringify(value)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (ArrayBuffer.isView(value)) {
|
|
11
|
-
return JSON.stringify(Array.from(value))
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return value
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function parseVector (value) {
|
|
18
|
-
if (value === null || value === undefined || Array.isArray(value)) {
|
|
19
|
-
return value
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (typeof value !== 'string') {
|
|
23
|
-
return value
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const parsed = JSON.parse(value)
|
|
28
|
-
if (Array.isArray(parsed)) {
|
|
29
|
-
return parsed
|
|
30
|
-
}
|
|
31
|
-
} catch {}
|
|
32
|
-
|
|
33
|
-
return value
|
|
34
|
-
}
|