createCommand method

  1. @override
String createCommand()
override
the text of the sql command that will create the object in the database

Implementation

@override
String createCommand() {
  StringBuffer sb = new StringBuffer();
  sb.write("CREATE TABLE IF NOT EXISTS `${this.name}` (");
  //columns
  for (DbColumn col in fields) {
    sb.write("${col.columnDefinition()} ,");
  }
  //forein keys
  for (_ForeignKey fk in this.FKs) {
    sb.write(
        "FOREIGN KEY (`${fk._coln.name}`) REFERENCES `${fk._tbl.name}` ON UPDATE ${_integrityRuleText(fk._onUpdate)} ON DELETE ${_integrityRuleText(fk._onDelete)},");
  }
  //primary key
  sb.write("PRIMARY KEY (`${this.fields[0].name}`)");
  sb.write(" )");
  //
  return sb.toString();
}