@mikro-orm/postgresql 7.0.0-dev.17 → 7.0.0-dev.170

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.
@@ -1,59 +0,0 @@
1
- import { raw, Type } from '@mikro-orm/core';
2
- export class FullTextType extends Type {
3
- regconfig;
4
- constructor(regconfig = 'simple') {
5
- super();
6
- this.regconfig = regconfig;
7
- }
8
- compareAsType() {
9
- return 'any';
10
- }
11
- getColumnType() {
12
- return 'tsvector';
13
- }
14
- // Use convertToDatabaseValue to prepare insert queries as this method has
15
- // access to the raw JS value. Return Knex#raw to prevent QueryBuilderHelper#mapData
16
- // from sanitizing the returned chaing of SQL functions.
17
- convertToDatabaseValue(value, platform, context) {
18
- // Don't convert to values from select queries to the to_tsvector notation
19
- // these should be compared as string using a special oparator or function
20
- // this behaviour is defined in Platform#getFullTextWhereClause.
21
- // This is always a string.
22
- if (typeof context === 'object' && context.fromQuery) {
23
- return value;
24
- }
25
- // Null values should not be processed
26
- if (!value) {
27
- return null;
28
- }
29
- // the object from that looks like { A: 'test data', B: 'test data2' ... }
30
- // must be converted to
31
- // setweight(to_tsvector(regconfig, value), A) || setweight(to_tsvector(regconfig, value), B)... etc
32
- // use Knex#raw to do binding of the values sanitization of the boundvalues
33
- // as we return a raw string which should not be sanitzed anymore
34
- if (typeof value === 'object') {
35
- const bindings = [];
36
- const sqlParts = [];
37
- for (const [weight, data] of Object.entries(value)) {
38
- // Check whether the weight is valid according to Postgres,
39
- // Postgres allows the weight to be upper and lowercase.
40
- if (!['A', 'B', 'C', 'D'].includes(weight.toUpperCase())) {
41
- throw new Error('Weight should be one of A, B, C, D.');
42
- }
43
- // Ignore all values that are not a string
44
- if (typeof data === 'string') {
45
- sqlParts.push('setweight(to_tsvector(?, ?), ?)');
46
- bindings.push(this.regconfig, data, weight);
47
- }
48
- }
49
- // Return null if the object has no valid strings
50
- if (sqlParts.length === 0) {
51
- return null;
52
- }
53
- // Join all the `setweight` parts using the PostgreSQL tsvector `||` concatenation operator
54
- return raw(sqlParts.join(' || '), bindings);
55
- }
56
- // if it's not an object, it is expected to be string which does not have to be wrapped in setweight.
57
- return raw('to_tsvector(?, ?)', [this.regconfig, value]);
58
- }
59
- }
package/types/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './FullTextType.js';
package/types/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './FullTextType.js';