Skip to content

Instantly share code, notes, and snippets.

@rikkimax
Created March 13, 2015 06:45
Show Gist options
  • Save rikkimax/9b545dd0feb0eecdd69d to your computer and use it in GitHub Desktop.
Save rikkimax/9b545dd0feb0eecdd69d to your computer and use it in GitHub Desktop.
module webdev.base.models.pagetemplate;
import webdev.base.orm;
import webdev.base.udas;
@ormTableName("PageTemplate")
struct PageTemplateModel {
@ormId {
/**
* The name of the page template.
*/
@ormPropertyHint(OrmPropertyTypes.String, 0)
@ormDescription("The name of the template. Should include location information such as file path.")
string name;
/**
* UTC+0 time of when this was last edited.
*/
@ormPropertyHint(OrmPropertyTypes.Integer, 4)
@ormDescription("When was this last changed. Do not change.")
long lastEdited;
}
@ormOptional
@ormPropertyHint(OrmPropertyTypes.Blob, 0)
@ormDescription("Optionally the template itself")
string value;
//mixin OrmModel!PageTemplateModel;
bool isValid() {
return lastEdited > 0 && name !is null; // custom validation
}
@ormCall {
void setValue(string value) {
this.value = value;
updateLastEdited;
}
void updateLastEdited() {
import webdev.base.util.time : utc0Time;
lastEdited = utc0Time();
}
}
@ormGetCall {
PageTemplateModel dup(string newName) {
PageTemplateModel ret = PageTemplateModel(newName, lastEdited, value);
ret.updateLastEdited;
return ret;
}
}
@ormQueryBy {
PageTemplateModel[] allPreviousValues() {
PageTemplateModel[] ret;
//TODO: some query here!
return ret;
}
}
static @ormQuery {
PageTemplateModel[] allLatestVersions() {
PageTemplateModel[] ret;
// TODO: some query here!
return ret;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment