sql-code-generator
Version:
Generate code from your SQL schema and queries for type safety and development speed.
36 lines • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTypeDefinitionFromResourceDeclaration = void 0;
const domain_1 = require("../../../domain");
const extractResourceTypeAndNameFromDDL_1 = require("./extractResourceTypeAndNameFromDDL");
const extractTypeDefinitionFromFunctionSql_1 = require("./function/extractTypeDefinitionFromFunctionSql");
const extractTypeDefinitionFromTableSql_1 = require("./table/extractTypeDefinitionFromTableSql");
const extractTypeDefinitionFromViewSql_1 = require("./view/extractTypeDefinitionFromViewSql");
const getTypeDefinitionFromResourceDeclaration = ({ declaration, }) => {
// 1. get name and type of resource
const { name, type } = (0, extractResourceTypeAndNameFromDDL_1.extractResourceTypeAndNameFromDDL)({
ddl: declaration.sql,
});
// 2. based on type, get the type definition
if (type === domain_1.ResourceType.TABLE) {
return (0, extractTypeDefinitionFromTableSql_1.extractTypeDefinitionFromTableSql)({
name,
sql: declaration.sql,
});
}
if (type === domain_1.ResourceType.FUNCTION) {
return (0, extractTypeDefinitionFromFunctionSql_1.extractTypeDefinitionFromFunctionSql)({
name,
sql: declaration.sql,
});
}
if (type === domain_1.ResourceType.VIEW) {
return (0, extractTypeDefinitionFromViewSql_1.extractTypeDefinitionFromViewSql)({
name,
sql: declaration.sql,
});
}
throw new Error(`resource type '${type}' is not yet supported`);
};
exports.getTypeDefinitionFromResourceDeclaration = getTypeDefinitionFromResourceDeclaration;
//# sourceMappingURL=getTypeDefinitionFromResourceDeclaration.js.map