UNPKG

@devbro/sql-generator

Version:
127 lines 3.42 kB
"use strict"; 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 Blueprint_exports = {}; __export(Blueprint_exports, { Blueprint: () => Blueprint, Column: () => Column }); module.exports = __toCommonJS(Blueprint_exports); var import_Expression = require("./Expression"); class Column { columnName = ""; properties = { type: "string", length: 255, nullable: false, unique: false, default: null }; constructor(columnName, type) { this.columnName = columnName; this.properties.type = type; } length(length) { this.properties.length = length; return this; } nullable(nullable = true) { this.properties.nullable = nullable; return this; } unique(unique = true) { this.properties.unique = unique; return this; } default(value) { this.properties.default = value; return this; } } class Blueprint { tableName = ""; columns = []; existingTable = false; primaryKeys = []; constructor() { } setTableName(tableName, existingTable = false) { this.tableName = tableName; this.existingTable = existingTable; } Boolean(columnName) { const rc = new Column(columnName, "boolean"); this.columns.push(rc); return rc; } char(columnName) { const rc = new Column(columnName, "char"); this.columns.push(rc); return rc; } string(columnName, length = 255) { const rc = new Column(columnName, "string"); rc.length(length); this.columns.push(rc); return rc; } text(columnName) { const rc = new Column(columnName, "text"); this.columns.push(rc); return rc; } integer(columnName) { const rc = new Column(columnName, "integer"); this.columns.push(rc); return rc; } float(columnName) { const rc = new Column(columnName, "float"); this.columns.push(rc); return rc; } double(columnName) { const rc = new Column(columnName, "double"); this.columns.push(rc); return rc; } id() { const rc = new Column("id", "serial"); this.columns.push(rc); this.primaryKeys.push("id"); return rc; } timestamps() { this.columns.push(new Column("created_at", "timestamp").default(new import_Expression.Expression("CURRENT_TIMESTAMP"))); this.columns.push(new Column("updated_at", "timestamp").default(new import_Expression.Expression("CURRENT_TIMESTAMP"))); } date(columnName) { const rc = new Column(columnName, "date"); this.columns.push(rc); return rc; } primary(keys) { this.primaryKeys = keys; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Blueprint, Column }); //# sourceMappingURL=Blueprint.js.map