MCPcopy
hub / github.com/drawdb-io/drawdb / getTypeString

Function getTypeString

src/utils/exportSQL/generic.js:49–190  ·  view source on GitHub ↗
(
  field,
  currentDb,
  dbms = DB.MYSQL,
  baseType = false,
)

Source from the content-addressed store, hash-verified

47}
48
49export function getTypeString(
50 field,
51 currentDb,
52 dbms = DB.MYSQL,
53 baseType = false,
54) {
55 if (dbms === DB.MYSQL) {
56 if (field.type === "UUID") {
57 return `VARCHAR(36)`;
58 }
59 if (
60 dbToTypes[currentDb][field.type].isSized ||
61 dbToTypes[currentDb][field.type].hasPrecision
62 ) {
63 return `${field.type}${field.size ? `(${field.size})` : ""}`;
64 }
65 if (field.type === "SET" || field.type === "ENUM") {
66 return `${field.type}(${field.values.map((v) => `"${v}"`).join(", ")})`;
67 }
68 if (!Object.keys(defaultTypes).includes(field.type)) {
69 return "JSON";
70 }
71 return field.type;
72 } else if (dbms === DB.POSTGRES) {
73 if (field.type === "SMALLINT" && field.increment) {
74 return "smallserial";
75 }
76 if (field.type === "INT" && field.increment) {
77 return "serial";
78 }
79 if (field.type === "BIGINT" && field.increment) {
80 return "bigserial";
81 }
82 if (field.type === "ENUM") {
83 return `${field.name}_t`;
84 }
85 if (field.type === "SET") {
86 return `${field.name}_t[]`;
87 }
88 if (field.type === "TIMESTAMP") {
89 return "TIMESTAMPTZ";
90 }
91 if (field.type === "DATETIME") {
92 return `timestamp`;
93 }
94 if (dbToTypes[currentDb][field.type].isSized && field.size) {
95 const type =
96 field.type === "BINARY"
97 ? "bit"
98 : field.type === "VARBINARY"
99 ? "bit varying"
100 : field.type.toLowerCase();
101 return `${type}(${field.size})`;
102 }
103 if (
104 dbToTypes[currentDb][field.type].hasPrecision &&
105 field.size &&
106 field.size.trim() !== ""

Callers 5

jsonToMySQLFunction · 0.85
jsonToPostgreSQLFunction · 0.85
jsonToMariaDBFunction · 0.85
jsonToSQLServerFunction · 0.85
jsonToOracleSQLFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected