createPostgresTable function

FutureOr createPostgresTable(
  1. Map fields,
  2. String tableName,
  3. String dbName,
  4. String host,
  5. int port,
  6. String username,
  7. String password,
)

Implementation

FutureOr createPostgresTable(
  Map fields,
  String tableName,
  String dbName,
  String host,
  int port,
  String username,
  String password,
) async {
  PostgreSQLConnection conn = PostgreSQLConnection(host, port, dbName,
      username: username, password: password);
  await conn.open();

  if (fields.length != 0) {
    var key = fields.keys.map((key) => '$key ${fields[key]}').join(', ');
    var startSql = 'CREATE TABLE IF NOT EXISTS $tableName ($key)';

    try {
      await conn.query(startSql);
      conn.close();
    } on PostgreSQLException catch (e) {
      print(e);
    }
  } else {
    print(
        '[ INFO ] Unknown error!! Please check the "model_definitions.yaml" file for any corrections.');
  }
}