You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB
JavaScript

const { makeKyselyHook } = require("kanel-kysely");
const { resolveType, escapeIdentifier } = require("kanel");
const { recase } = require("@kristiandupont/recase");
const toPascalCase = recase("snake", "pascal");
module.exports = {
connection:
"postgres://neondb_owner:npg_sOVmj8vWq2zG@ep-withered-king-adiz9gpi-pooler.c-2.us-east-1.aws.neon.tech:5432/neondb?sslmode=require&channel_binding=true",
enumStyle: "type",
outputPath: "./database/generated",
preRenderHooks: [makeKyselyHook()],
generateIdentifierType: (column, details, config) => {
const name = escapeIdentifier(
toPascalCase(details.name) + toPascalCase(column.name)
);
const innerType = resolveType(column, details, {
...config,
// Explicitly disable identifier resolution so we get the actual inner type here
generateIdentifierType: undefined,
});
const imports = [];
let type = innerType;
if (typeof innerType === "object") {
// Handle non-primitives
type = innerType.name;
imports.push(...innerType.typeImports);
}
return {
declarationType: "typeDeclaration",
name,
exportAs: "named",
typeDefinition: [`${type}`],
typeImports: imports,
comment: [`Identifier type for ${details.schemaName}.${details.name}`],
};
},
customTypeMap: {
"pg_catalog.timestamp": "string",
},
};