using InvercargillSql.Orm.Projections; using Invercargill.DataStructures; using Spry.Authorisation; using Invercargill; using Invercargill.Expressions; namespace Spry.Authentication { public class UserProjection : Object, Identity { public Element identifier { owned get { return new NativeElement(id); } } public string username { get { return _username; } } public ImmutableLot permissions { owned get { return _permissions.to_immutable_buffer(); } } public Invercargill.Properties data { owned get { var props = new DataStructures.PropertyDictionary(); props.set_native("email", email); props.set_native("forename", forename); props.set_native("surname", surname); props.set_native("date_of_birth", date_of_birth); props.set_native("created", created); props.set_native("modified", modified); return props; }} public int64 id { get; set; } public string email { get; set; } public string forename { get; set; } public string surname { get; set; } public string password_hash { get; set; } public DateTime date_of_birth { get; set; } public DateTime created { get; set; } public DateTime modified { get; set; } public bool enabled { get; set; } private string _username; private ImmutableBuffer _permissions; public static void projection_mapping(ProjectionBuilder cfg) throws Error { cfg.source("u") .select("id", expr("u.id"), (o, v) => o.id = v) .select("username", expr("u.username"), (o, v) => o._username = v) .select("email", expr("u.email"), (o, v) => o.email = v) .select("forename", expr("u.forename"), (o, v) => o.forename = v) .select("surname", expr("u.surname"), (o, v) => o.surname = v) .select("password_hash", expr("u.password_hash"), (o, v) => o.password_hash = v) .select("date_of_birth", expr("u.date_of_birth"), (o, v) => o.date_of_birth = v) .select("created", expr("u.created"), (o, v) => o.created = v) .select("modified", expr("u.modified"), (o, v) => o.modified = v) .select("enabled", expr("u.enabled"), (o, v) => o.enabled = v) .join("p", expr("p.user_id == u.id")) .select_many("permissions", expr("p.permission"), (o, v) => o._permissions = v.to_immutable_buffer()); } } }