MCPcopy
hub / github.com/sequelize/sequelize / STRING

Class STRING

lib/data-types.js:53–90  ·  view source on GitHub ↗

* STRING A variable length string

Source from the content-addressed store, hash-verified

51 * STRING A variable length string
52 */
53class STRING extends ABSTRACT {
54 /**
55 * @param {number} [length=255] length of string
56 * @param {boolean} [binary=false] Is this binary?
57 */
58 constructor(length, binary) {
59 super();
60 const options = typeof length === 'object' && length || { length, binary };
61 this.options = options;
62 this._binary = options.binary;
63 this._length = options.length || 255;
64 }
65 toSql() {
66 return joinSQLFragments([
67 `VARCHAR(${this._length})`,
68 this._binary && 'BINARY'
69 ]);
70 }
71 validate(value) {
72 if (Object.prototype.toString.call(value) !== '[object String]') {
73 if (this.options.binary && Buffer.isBuffer(value) || typeof value === 'number') {
74 return true;
75 }
76 throw new sequelizeErrors.ValidationError(util.format('%j is not a valid string', value));
77 }
78 return true;
79 }
80
81 get BINARY() {
82 this._binary = true;
83 this.options.binary = true;
84 return this;
85 }
86
87 static get BINARY() {
88 return new this().BINARY;
89 }
90}
91
92/**
93 * CHAR A fixed length string

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…