gnablib
Version:
A lean, zero dependency library to provide a useful base for your project.
2 lines • 1.61 kB
JavaScript
/*! Copyright 2023-2024 the gnablib contributors MPL-1.1 */
import{ColType as e}from"./ColType.js";import{ACudColType as i}from"./ACudColType.js";import{FromBinResult as t}from"../../primitive/FromBinResult.js";import{DateTimeLocal as n}from"../../datetime/dt.js";import{BitWriter as r}from"../../primitive/BitWriter.js";import{BitReader as o}from"../../primitive/BitReader.js";import{TypeProblem as l}from"../../error/probs/TypeProblem.js";import{ContentError as s}from"../../error/ContentError.js";export class DateTimeCol extends i{constructor(i=!1){super(i),this.mysqlType="BIGINT",this.sqliteType="INT8",this.postgresType="timestamp with time zone",this.cudType="datetime",this._colType=e.DateTime}cudByteSize(){return 8}valid(e){if(null==e&&!this.nullable)return l.Null("input")}unknownBin(e){if(!e){if(!this.nullable)throw new s("cannot be null","DateTime",void 0);return new Uint8Array([0])}const i=new Uint8Array(Math.ceil(n.serialBits/8)+1),t=r.mount(i);return t.pushNumberBE(Math.ceil(n.serialBits/8),8),e.serialize(t),i}binUnknown(e,i){var r;if(i+1>e.length)return new t(0,void 0,"DateTimeCol.binUnknown unable to find length");const l=e[i++];if(0===l)return this.nullable?new t(1,void 0):new t(0,void 0,"DateTimeCol.binUnknown cannot be null");if(8!==l)return new t(0,void 0,`DateTimeCol.binUnknown invalid length (8 got ${l})`);if(i+l>e.length)return new t(0,void 0,"DateTimeCol.binUnknown missing data");const s=o.mount(e.subarray(i));try{const e=n.deserialize(s);return new t(1+l,e)}catch(e){return new t(0,void 0,"DateTimeCol.binUnknown bad value: "+(null!==(r=e.message)&&void 0!==r?r:""))}}}