Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Last active May 30, 2018 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphicbeacon/1caa063532e335584925f2d18683bc50 to your computer and use it in GitHub Desktop.
Save graphicbeacon/1caa063532e335584925f2d18683bc50 to your computer and use it in GitHub Desktop.
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 4)" post on Medium (4)
// This goes in lib/utils/utils.dart
import 'dart:async';
import 'package:aqueduct/aqueduct.dart';
Future createDatabaseSchema(ManagedContext context, bool isTemporary) async {
try {
var builder = new SchemaBuilder.toSchema(
context.persistentStore, new Schema.fromDataModel(context.dataModel),
isTemporary: isTemporary);
for (var cmd in builder.commands) {
await context.persistentStore.execute(cmd);
}
} catch (e) {
// Database may already exist
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment