Parse types for postgres
This commit is contained in:
parent
9a1c086870
commit
6172d48bf5
@ -775,7 +775,7 @@ export default function ControlPanel(props) {
|
||||
relationships: relationships,
|
||||
notes: notes,
|
||||
subjectAreas: areas,
|
||||
types: types
|
||||
types: types,
|
||||
},
|
||||
null,
|
||||
2
|
||||
@ -797,6 +797,7 @@ export default function ControlPanel(props) {
|
||||
const src = jsonToMySQL({
|
||||
tables: tables,
|
||||
references: relationships,
|
||||
types: types,
|
||||
});
|
||||
setExportData((prev) => ({
|
||||
...prev,
|
||||
@ -811,6 +812,7 @@ export default function ControlPanel(props) {
|
||||
const src = jsonToPostgreSQL({
|
||||
tables: tables,
|
||||
references: relationships,
|
||||
types: types,
|
||||
});
|
||||
setExportData((prev) => ({
|
||||
...prev,
|
||||
|
@ -177,7 +177,19 @@ function jsonToMySQL(obj) {
|
||||
}
|
||||
|
||||
function jsonToPostgreSQL(obj) {
|
||||
return `${obj.tables
|
||||
return `${obj.types.map(
|
||||
(type) =>
|
||||
`${type.fields
|
||||
.filter((f) => f.type === "ENUM" || f.type === "SET")
|
||||
.map(
|
||||
(f) =>
|
||||
`CREATE TYPE "${f.name}_t" AS ENUM (${f.values
|
||||
.map((v) => `'${v}'`)
|
||||
.join(", ")});\n`
|
||||
)}CREATE TYPE ${type.name} AS (\n${type.fields
|
||||
.map((f) => `\t${f.name} ${getTypeString(f, "postgres")}`)
|
||||
.join("\n")}\n);`
|
||||
)}\n${obj.tables
|
||||
.map(
|
||||
(table) =>
|
||||
`${table.comment === "" ? "" : `/**\n${table.comment}\n*/\n`}${
|
||||
|
Loading…
Reference in New Issue
Block a user