MCPcopy Create free account
hub / github.com/NobleMajo/al-sql / createColumnQuery

Method createColumnQuery

src/pg.ts:289–322  ·  view source on GitHub ↗
(
        column: Column
    )

Source from the content-addressed store, hash-verified

287 }
288
289 createColumnQuery(
290 column: Column
291 ): string {
292 let line: string = column.name + " " + column.type.toUpperCase()
293 if (column.size) {
294 line += "(" + column.size + ")"
295 }
296 if (column.unique) {
297 line += " UNIQUE"
298 } else if (column.primaryKey) {
299 line += " PRIMARY KEY"
300 }
301 if (column.nullable) {
302 line += " NULL"
303 } else {
304 line += " NOT NULL"
305 }
306 const type = typeof column.default
307 if (type != "undefined") {
308 line += " DEFAULT "
309 if (column.default == null) {
310 line += "NULL"
311 } else if (type == "boolean") {
312 line += column.default == true ? "TRUE" : "FALSE"
313 } else if (type == "number") {
314 line += Number(column.default)
315 } else if (type == "string") {
316 line += "'" + (column.default as string).split("'").join("\\'") + "'"
317 } else {
318 throw new Error("Type of default value is not string, number, boolean or null!")
319 }
320 }
321 return line
322 }
323
324 createTableQuery(
325 table: SqlTable

Callers 1

createTableQueryMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected