Skip to content

Instantly share code, notes, and snippets.

@xxgreg
Last active December 15, 2015 18:59
Show Gist options
  • Save xxgreg/5307940 to your computer and use it in GitHub Desktop.
Save xxgreg/5307940 to your computer and use it in GitHub Desktop.
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