-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathsparsevec.js
More file actions
61 lines (51 loc) · 1.43 KB
/
sparsevec.js
File metadata and controls
61 lines (51 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { inherits } from 'node:util';
import { Sequelize, DataTypes, Utils } from 'sequelize';
import { sparsevecType, sparsevecToSql, sparsevecFromSql } from '../utils.js';
/** @import { SparseVector } from '../index.js' */
// @ts-ignore
const PgTypes = DataTypes.postgres;
const ABSTRACT = DataTypes.ABSTRACT.prototype.constructor;
class SPARSEVEC extends ABSTRACT {
/**
* @param {number} [dimensions]
*/
constructor(dimensions) {
super();
this._dimensions = dimensions;
}
toSql() {
return sparsevecType(this._dimensions).toUpperCase();
}
/**
* @param {?SparseVector} value
*/
_stringify(value) {
return sparsevecToSql(value);
}
/**
* @param {?string} value
*/
static parse(value) {
return sparsevecFromSql(value);
}
}
SPARSEVEC.prototype.key = SPARSEVEC.key = 'sparsevec';
// @ts-ignore
DataTypes.SPARSEVEC = Utils.classToInvokable(SPARSEVEC);
// @ts-ignore
DataTypes.SPARSEVEC.types.postgres = ['sparsevec'];
PgTypes.SPARSEVEC = function SPARSEVEC() {
if (!(this instanceof PgTypes.SPARSEVEC)) {
return new PgTypes.SPARSEVEC();
}
// @ts-ignore
DataTypes.SPARSEVEC.apply(this, arguments);
};
inherits(PgTypes.SPARSEVEC, DataTypes.SPARSEVEC);
// @ts-ignore
PgTypes.SPARSEVEC.parse = DataTypes.SPARSEVEC.parse;
PgTypes.SPARSEVEC.types = {postgres: ['sparsevec']};
PgTypes.SPARSEVEC.key = 'sparsevec';
// for migrations
// @ts-ignore
Sequelize.SPARSEVEC ??= DataTypes.SPARSEVEC;