Last active
December 15, 2015 18:59
-
-
Save xxgreg/5307940 to your computer and use it in GitHub Desktop.
This file contains 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
Create the files shown below, make sure dart-sdk/bin is in your path and run: | |
pub install | |
This will fetch the source for the postgresql library, and put it in a sub-directory called packages. | |
Then run the program: | |
dart main.dart | |
----- pubspec.yaml | |
name: postgres_example | |
dependencies: | |
postgresql: any | |
----- main.dart | |
import 'dart:async'; | |
import 'dart:io'; | |
import 'package:postgresql/postgresql.dart'; | |
void main() { | |
var uri = 'postgres://testdb:password@localhost:5432/testdb'; | |
connect(uri).then((conn) { | |
conn.query('select color from crayons').toList().then((rows) { | |
for (var row in rows) { | |
print(row.color); // Refer to columns by name, | |
print(row[0]); // Or by column index. | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment