drizzle-orm
Version:
Drizzle ORM package for SQL databases
158 lines • 4.99 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var integer_exports = {};
__export(integer_exports, {
SQLiteBaseInteger: () => SQLiteBaseInteger,
SQLiteBaseIntegerBuilder: () => SQLiteBaseIntegerBuilder,
SQLiteBoolean: () => SQLiteBoolean,
SQLiteBooleanBuilder: () => SQLiteBooleanBuilder,
SQLiteInteger: () => SQLiteInteger,
SQLiteIntegerBuilder: () => SQLiteIntegerBuilder,
SQLiteTimestamp: () => SQLiteTimestamp,
SQLiteTimestampBuilder: () => SQLiteTimestampBuilder,
int: () => int,
integer: () => integer
});
module.exports = __toCommonJS(integer_exports);
var import_entity = require("../../entity.cjs");
var import_sql = require("../../sql/sql.cjs");
var import_utils = require("../../utils.cjs");
var import_common = require("./common.cjs");
class SQLiteBaseIntegerBuilder extends import_common.SQLiteColumnBuilder {
static [import_entity.entityKind] = "SQLiteBaseIntegerBuilder";
constructor(name, dataType, columnType) {
super(name, dataType, columnType);
this.config.autoIncrement = false;
}
primaryKey(config) {
if (config?.autoIncrement) {
this.config.autoIncrement = true;
}
this.config.hasDefault = true;
return super.primaryKey();
}
}
class SQLiteBaseInteger extends import_common.SQLiteColumn {
static [import_entity.entityKind] = "SQLiteBaseInteger";
autoIncrement = this.config.autoIncrement;
getSQLType() {
return "integer";
}
}
class SQLiteIntegerBuilder extends SQLiteBaseIntegerBuilder {
static [import_entity.entityKind] = "SQLiteIntegerBuilder";
constructor(name) {
super(name, "number", "SQLiteInteger");
}
build(table) {
return new SQLiteInteger(
table,
this.config
);
}
}
class SQLiteInteger extends SQLiteBaseInteger {
static [import_entity.entityKind] = "SQLiteInteger";
}
class SQLiteTimestampBuilder extends SQLiteBaseIntegerBuilder {
static [import_entity.entityKind] = "SQLiteTimestampBuilder";
constructor(name, mode) {
super(name, "date", "SQLiteTimestamp");
this.config.mode = mode;
}
/**
* @deprecated Use `default()` with your own expression instead.
*
* Adds `DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer))` to the column, which is the current epoch timestamp in milliseconds.
*/
defaultNow() {
return this.default(import_sql.sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`);
}
build(table) {
return new SQLiteTimestamp(
table,
this.config
);
}
}
class SQLiteTimestamp extends SQLiteBaseInteger {
static [import_entity.entityKind] = "SQLiteTimestamp";
mode = this.config.mode;
mapFromDriverValue(value) {
if (this.config.mode === "timestamp") {
return new Date(value * 1e3);
}
return new Date(value);
}
mapToDriverValue(value) {
const unix = value.getTime();
if (this.config.mode === "timestamp") {
return Math.floor(unix / 1e3);
}
return unix;
}
}
class SQLiteBooleanBuilder extends SQLiteBaseIntegerBuilder {
static [import_entity.entityKind] = "SQLiteBooleanBuilder";
constructor(name, mode) {
super(name, "boolean", "SQLiteBoolean");
this.config.mode = mode;
}
build(table) {
return new SQLiteBoolean(
table,
this.config
);
}
}
class SQLiteBoolean extends SQLiteBaseInteger {
static [import_entity.entityKind] = "SQLiteBoolean";
mode = this.config.mode;
mapFromDriverValue(value) {
return Number(value) === 1;
}
mapToDriverValue(value) {
return value ? 1 : 0;
}
}
function integer(a, b) {
const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);
if (config?.mode === "timestamp" || config?.mode === "timestamp_ms") {
return new SQLiteTimestampBuilder(name, config.mode);
}
if (config?.mode === "boolean") {
return new SQLiteBooleanBuilder(name, config.mode);
}
return new SQLiteIntegerBuilder(name);
}
const int = integer;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
SQLiteBaseInteger,
SQLiteBaseIntegerBuilder,
SQLiteBoolean,
SQLiteBooleanBuilder,
SQLiteInteger,
SQLiteIntegerBuilder,
SQLiteTimestamp,
SQLiteTimestampBuilder,
int,
integer
});
//# sourceMappingURL=integer.cjs.map
;