-
Notifications
You must be signed in to change notification settings - Fork 0
Constraint types seems to be missing #1
Description
UPDATE: seems that we need to switch on Enum ConstrType, and create helper methods named based on something like <Type>_<Enum>, e.g. Constraint_CONSTR_FOREIGN or some case() method variation for better readability.
Seems that the polymorphic nature of Constraint via ConstrType has left those names out of the protobuf, for our own implementation:
Likely this means that likely we don't need to add them directly, but consider how naming conventions should work in general for these types of scenarios
-
ReferenceConstraint -
ConstraintStmt -
ExclusionConstraint
example of ConstraintStmt in pgsql-parser, first you'll see that Constraint is the actual node:
Constraint(node: Constraint, context = {}) {
const output = [];
if (node.contype === 'CONSTR_FOREIGN') {
output.push(this.ReferenceConstraint(node, context));
} else {
output.push(this.ConstraintStmt(node, context));
}
}the others are technically our own made up names. ConstraintStmt happens to be a generic way to insert certain general onstraint utilties, and even supports other constraint types. Essentially, ReferenceConstraint, ConstraintStmt, ExclusionConstraint are helpers for Constraint:
['ConstraintStmt'](node) {
const output = [];
const constraint = getConstraintFromConstrType(node.contype);
if (node.conname) {
output.push('CONSTRAINT');
output.push(node.conname);
if (!node.pktable) {
output.push(constraint);
}
} else if (node.contype === 'CONSTR_IDENTITY') {
// IDENTITY
output.push('GENERATED');
if (node.generated_when == 'a') {
output.push('ALWAYS AS');
} else {
output.push('BY DEFAULT AS');
}
output.push('IDENTITY');
const options = unwrapList(node.options);
if (options && options.length) {
output.push('(');
output.push(this.list(options, ' ', '', 'generated'));
output.push(')');
}
} else if (node.contype === 'CONSTR_GENERATED') {
output.push('GENERATED');
if (node.generated_when == 'a') {
output.push('ALWAYS AS');
}
} else {
output.push(constraint);
}
return output.join(' ');
}