Created
June 30, 2014 10:56
-
-
Save kurorido/6b0b056ae1d46f5da8a2 to your computer and use it in GitHub Desktop.
insert 1M records into postgresSQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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