Parse types for postgres
This commit is contained in:
parent
9a1c086870
commit
6172d48bf5
@ -775,7 +775,7 @@ export default function ControlPanel(props) {
|
|||||||
relationships: relationships,
|
relationships: relationships,
|
||||||
notes: notes,
|
notes: notes,
|
||||||
subjectAreas: areas,
|
subjectAreas: areas,
|
||||||
types: types
|
types: types,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
2
|
2
|
||||||
@ -797,6 +797,7 @@ export default function ControlPanel(props) {
|
|||||||
const src = jsonToMySQL({
|
const src = jsonToMySQL({
|
||||||
tables: tables,
|
tables: tables,
|
||||||
references: relationships,
|
references: relationships,
|
||||||
|
types: types,
|
||||||
});
|
});
|
||||||
setExportData((prev) => ({
|
setExportData((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
@ -811,6 +812,7 @@ export default function ControlPanel(props) {
|
|||||||
const src = jsonToPostgreSQL({
|
const src = jsonToPostgreSQL({
|
||||||
tables: tables,
|
tables: tables,
|
||||||
references: relationships,
|
references: relationships,
|
||||||
|
types: types,
|
||||||
});
|
});
|
||||||
setExportData((prev) => ({
|
setExportData((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
|
@ -177,7 +177,19 @@ function jsonToMySQL(obj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function jsonToPostgreSQL(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(
|
.map(
|
||||||
(table) =>
|
(table) =>
|
||||||
`${table.comment === "" ? "" : `/**\n${table.comment}\n*/\n`}${
|
`${table.comment === "" ? "" : `/**\n${table.comment}\n*/\n`}${
|
||||||
|
Loading…
Reference in New Issue
Block a user