Parse types for postgres

This commit is contained in:
1ilit 2023-09-19 15:51:36 +03:00
parent 9a1c086870
commit 6172d48bf5
2 changed files with 16 additions and 2 deletions

View File

@ -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,

View File

@ -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`}${