/* TODO: add support for has_many and belongs_to. * - has_many means it will lookup by the local structures key for _key. * e.g. from person, * look up all contacts with a person_id = self.id * - belongs_to means it will lookup the given object by the specified key in itself * e.g. from address_map, * look up all people with a person_id of address_map.person.id */ /* My contacts will only have one real name, but may have multiple nicks */ struct person { string name_first = 1; string name_middle = 2; string name_last = 3; string name_prefix = 4; string name_suffix = 5; string name_common = 6; /*^* index=person:name_last:string; */ /*^* index=person:name_first:string; */ /* Note that we have many nicknames and to delete them if we're deleted */ /*^* has_many=person:nickname:del; */ /* Note, this will lookup contact by person_id. Yay, convention. */ /*^* has_many=person:contact:del; */ /* Addresses may be shared */ /*^* has_many=person:address_map:del; */ } /* While nicknames are by no means unique, they are also short, unlike addresses. * We'll tolerate double storing nicks for the convience of one layer of dereferencing. */ struct nickname { int64 person_id = 1; string name = 2; /*^* index=nickname:person_id:int64; */ } /* Since address are not 1:1, multiple people may work or live at the same * address, we use an intermediary database for cross referencing * NOTE: _map and _id are treat as special names which will later result in * automagic derefencing through a combination of generated C and JS magic. */ struct address_map { int64 address_id = 1; int64 person_id = 2; /*^* index=address_map:person_id:int64; */ /*^* index=address_map:address_id:int64; */ /*^* belongs_to=address_map:address:address_id; */ /*^* belongs_to=address_map:person:person_id; */ } struct address { int number = 1; string street = 2; int unit = 3; string city = 4; string postcode = 5; string country = 6; string type = 8; /* home, work, etc */ /*^* has_many=address:address_map:del; */ } struct contact { string type = 1; /* often email, cell, etc */ string data = 2; /* Contact info should be 1:1 */ int64 person_id = 3; /*^* index=contact:person_id:int64; */ }