Joe Conway

Aqueduct 2.1: Data Validation

May 1, 2017

The latest in Aqueduct for Dart news. The most recent release of the Dart server-side framework Aqueduct adds behavior for validating data before it is inserted or updated in a database and fixes issues when running on Windows OS.

Database object properties may now have validation metadata that gets checked before they are sent to a database. Here’s an example:

class Tweet extends ManagedObject<_Tweet> implements _Tweet {
  @override
  void willInsert() {
    createdAt = new DateTime.now().toUtc();
  }
}
class _Tweet {
  @managedPrimaryKey
  int id;

  @Validate.length(lessThan: 140)  
  String body;

  @Validate.oneOf(const ["tweet", "reply", "retweet"])
  @ManagedColumnAttributes(indexed: true)
  String kind;

  @ManagedColumnAttributes(indexed: true)
  DateTime createdAt;
}

Related: Why we built Aqueduct

For more details on validation, see the documentation guide for validations.

Windows users can now use the aqueduct serve command.

Published May 1, 2017
Joe Conway

CEO & Founder at Stable Kernel

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *