Skip to content

Validation

高新成 edited this page Nov 20, 2018 · 3 revisions

Custom Table Model

@Table("UserInfo")
class UserInfo : Model {

    mixin MakeModel;

    @AutoIncrement @PrimaryKey 
    int id;

    @Length(0,50,"length must be between 0 and 50")
    string nickName;
    @Max(150)
    int age;

}

Example

   auto query = em.createQuery!UserInfo("select u from UserInfo u");
   auto uinfos = query.getResultList();
   foreach(u;uinfos)
   {
     auto result = u.valid();

    if (result.isValid() == false)
    {
        import std.stdio : writeln;
        foreach(key, message; result.messages())
        {
            writeln("%s: %s", key, message);
        }
    }
    }
Clone this wiki locally