toPgSql method

String toPgSql({
  1. required String tableName,
})

Implementation

String toPgSql({
  required String tableName,
}) {
  var out = '';

  var refColumnsFmt = referenceColumns.map((e) => '"$e"');

  out += 'ALTER TABLE ONLY "$tableName"\n';
  out += '    ADD CONSTRAINT "$constraintName"\n';
  out += '    FOREIGN KEY("${columns.join(', ')}")\n';
  out += '    REFERENCES "$referenceTable"(${refColumnsFmt.join(', ')})';

  String? delete = onDelete?.toPgSqlAction();
  if (delete != null) {
    out += '\n';
    out += '    ON DELETE $delete';
  }

  String? update = onUpdate?.toPgSqlAction();
  if (update != null) {
    out += '\n';
    out += '    ON UPDATE $update';
  }

  out += ';\n';

  return out;
}