MCPcopy
hub / github.com/sequelize/sequelize / NUMBER

Class NUMBER

lib/data-types.js:165–242  ·  view source on GitHub ↗

* Base number type which is used to build other types

Source from the content-addressed store, hash-verified

163 * Base number type which is used to build other types
164 */
165class NUMBER extends ABSTRACT {
166 /**
167 * @param {object} options type options
168 * @param {string|number} [options.length] length of type, like `INT(4)`
169 * @param {boolean} [options.zerofill] Is zero filled?
170 * @param {boolean} [options.unsigned] Is unsigned?
171 * @param {string|number} [options.decimals] number of decimal points, used with length `FLOAT(5, 4)`
172 * @param {string|number} [options.precision] defines precision for decimal type
173 * @param {string|number} [options.scale] defines scale for decimal type
174 */
175 constructor(options = {}) {
176 super();
177 if (typeof options === 'number') {
178 options = {
179 length: options
180 };
181 }
182 this.options = options;
183 this._length = options.length;
184 this._zerofill = options.zerofill;
185 this._decimals = options.decimals;
186 this._precision = options.precision;
187 this._scale = options.scale;
188 this._unsigned = options.unsigned;
189 }
190 toSql() {
191 let result = this.key;
192 if (this._length) {
193 result += `(${this._length}`;
194 if (typeof this._decimals === 'number') {
195 result += `,${this._decimals}`;
196 }
197 result += ')';
198 }
199 if (this._unsigned) {
200 result += ' UNSIGNED';
201 }
202 if (this._zerofill) {
203 result += ' ZEROFILL';
204 }
205 return result;
206 }
207 validate(value) {
208 if (!Validator.isFloat(String(value))) {
209 throw new sequelizeErrors.ValidationError(util.format(`%j is not a valid ${this.key.toLowerCase()}`, value));
210 }
211 return true;
212 }
213 _stringify(number) {
214 if (typeof number === 'number' || typeof number === 'boolean' || number === null || number === undefined) {
215 return number;
216 }
217 if (typeof number.toString === 'function') {
218 return number.toString();
219 }
220 return number;
221 }
222

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…