Skip to content

Instantly share code, notes, and snippets.

@kurorido
Created June 30, 2014 10:56
Show Gist options
  • Save kurorido/6b0b056ae1d46f5da8a2 to your computer and use it in GitHub Desktop.
Save kurorido/6b0b056ae1d46f5da8a2 to your computer and use it in GitHub Desktop.
insert 1M records into postgresSQL
void preparePostgreSQL() {
print("Testing Insert into postgresql...");
var uri = 'postgres://name:[email protected]:5432/mydb';
connect(uri).then((conn) {
//conn.execute("create table data (id int, name text, description text, PRIMARY KEY(id)); ").whenComplete(() {
// conn.close();
//});
int startTime = new DateTime.now().millisecondsSinceEpoch;
List<Future> futures = new List();
String sql = "";
for (var i = 0; i < 1000000; i++) {
String key = i.toString();
String name = "name" + i.toString();
String desc = "desc" + i.toString();
sql += "insert into data (id, name, description) values ("+ key +",'" + name + "','" + desc + "');";
}
//print(sql);
futures.add(conn.execute(sql));
Future.wait(futures).then((_) {
int endTime = new DateTime.now().millisecondsSinceEpoch;
int timeCost = endTime - startTime;
print(timeCost.toString() + "ms");
}).whenComplete(() {
conn.close();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment