Last active
May 30, 2018 18:27
-
-
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 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
// 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