@technicity/data-service-generator 0.23.0-next.3 → 0.23.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generation/generate.js +2 -27
- package/package.json +1 -1
|
@@ -1800,32 +1800,6 @@ const getPgEnumDefinition = (0, memoize_1.default)(async function getPgEnumDefin
|
|
|
1800
1800
|
const labels = rows.map((r) => String(r.enumlabel).replace(/'/g, "''"));
|
|
1801
1801
|
return "enum('" + labels.join("', '") + "')";
|
|
1802
1802
|
}, (udtName) => getCtx().runId + ":" + udtName);
|
|
1803
|
-
/** List enum type names in the public schema (for building CREATE TYPE DDL). */
|
|
1804
|
-
async function getPublicEnumTypeNames() {
|
|
1805
|
-
const { dialect, query } = getCtx();
|
|
1806
|
-
if (dialect !== "postgresql")
|
|
1807
|
-
return [];
|
|
1808
|
-
const rows = await query(`SELECT t.typname FROM pg_type t
|
|
1809
|
-
JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid
|
|
1810
|
-
WHERE n.nspname = 'public' AND t.typtype = 'e'
|
|
1811
|
-
ORDER BY t.typname`);
|
|
1812
|
-
return rows.map((r) => String(r.typname));
|
|
1813
|
-
}
|
|
1814
|
-
const getPgCreateTypeEnumStatement = (0, memoize_1.default)(async function getPgCreateTypeEnumStatement(typname) {
|
|
1815
|
-
const { dialect, query } = getCtx();
|
|
1816
|
-
if (dialect !== "postgresql")
|
|
1817
|
-
return null;
|
|
1818
|
-
const rows = await query(`SELECT e.enumlabel FROM pg_enum e
|
|
1819
|
-
JOIN pg_type t ON e.enumtypid = t.oid
|
|
1820
|
-
JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid
|
|
1821
|
-
WHERE t.typname = $1 AND n.nspname = 'public'
|
|
1822
|
-
ORDER BY e.enumsortorder`, [typname]);
|
|
1823
|
-
if (rows.length === 0)
|
|
1824
|
-
return null;
|
|
1825
|
-
const quoted = typname.replace(/"/g, '""');
|
|
1826
|
-
const labels = rows.map((r) => "'" + String(r.enumlabel).replace(/'/g, "''") + "'");
|
|
1827
|
-
return `CREATE TYPE "${quoted}" AS ENUM (${labels.join(", ")});`;
|
|
1828
|
-
}, (typname) => getCtx().runId + ":" + typname);
|
|
1829
1803
|
const getTableMeta = (0, memoize_1.default)(async function getTableMeta(table) {
|
|
1830
1804
|
const { dialect, query } = getCtx();
|
|
1831
1805
|
if (dialect === "mysql") {
|
|
@@ -1864,7 +1838,7 @@ const getTableMeta = (0, memoize_1.default)(async function getTableMeta(table) {
|
|
|
1864
1838
|
];
|
|
1865
1839
|
const enumDefs = await Promise.all(udtNames.map((udt) => getPgEnumDefinition(udt)));
|
|
1866
1840
|
const enumMap = new Map(udtNames.map((udt, i) => [udt, enumDefs[i] ?? "varchar(255)"]));
|
|
1867
|
-
|
|
1841
|
+
const cols = columns.map((c) => {
|
|
1868
1842
|
let type;
|
|
1869
1843
|
if (c.data_type === "USER-DEFINED" && c.udt_name != null) {
|
|
1870
1844
|
type = enumMap.get(c.udt_name) ?? "character varying(255)";
|
|
@@ -1887,6 +1861,7 @@ const getTableMeta = (0, memoize_1.default)(async function getTableMeta(table) {
|
|
|
1887
1861
|
: {})
|
|
1888
1862
|
};
|
|
1889
1863
|
});
|
|
1864
|
+
return _.sortBy((c) => c.Field, cols);
|
|
1890
1865
|
}
|
|
1891
1866
|
throw new Error("Unsupported dialect: " + dialect);
|
|
1892
1867
|
}, (table) => getCtx().runId + ":" + table);
|