I'm designing a server control panel and right now my table structure is basically something like this:
users table:
userid
username
password
addon domains table:
addondomainid
owneruserid
domainname
And so on. Basically a table for each type of data, with the proper fields for that object. A very typical way of doing things.
I just had an idea, to treat everything as an "object". So a user is an object, an addon domain is an object, an alias is an object, a DNS zone is an object, and a DNS zone entry is an object etc... In lot of cases objects would contain other objects. For example a user would contain many addon domain objects, and these addon domain objects would contain alias objects and so on...
If I structure this well it will make coding easier as I'd have standardized ways to query these objects.
The DB structure would also change to something like this:
objects table:
objectID
parentobjectID
objecttype
Fields Table:
objectID
Fieldname
Fieldvalue
Basically rather then have specific tables with specific fields, it would be a very general set of tables that are "catch all" if you will and have an actual table for fields. In fact I think this may be better as it will allow to add "modules" without much modification to the DB structure. However it would involve larger queries. For example if I want to list all the domains owned by a certain user I need to do a join query to get all fields matching objects of type domain matching the ID of the user.
But should I really be concerned about the speed of my queries these days? Even a bunch of large queries, we're still talking less then 1 second here, and DBs are made for speed and made to be queried. I've always tried to minimize the amount of queries in my programs but I'm wondering if I may be concentrating too hard on that, when I could instead let that slide a tad while maintaining easier to deal with code.
Just wondering how most people approach these things. If it matters, my program is written in C++. I'm only really working at the structure level now, so I want to build a solid foundation and make it super easy to add new modules and if I use my proposed system I will actually be able to add new modules without even modifying the DB, which I think is pretty cool.
users table:
userid
username
password
addon domains table:
addondomainid
owneruserid
domainname
And so on. Basically a table for each type of data, with the proper fields for that object. A very typical way of doing things.
I just had an idea, to treat everything as an "object". So a user is an object, an addon domain is an object, an alias is an object, a DNS zone is an object, and a DNS zone entry is an object etc... In lot of cases objects would contain other objects. For example a user would contain many addon domain objects, and these addon domain objects would contain alias objects and so on...
If I structure this well it will make coding easier as I'd have standardized ways to query these objects.
The DB structure would also change to something like this:
objects table:
objectID
parentobjectID
objecttype
Fields Table:
objectID
Fieldname
Fieldvalue
Basically rather then have specific tables with specific fields, it would be a very general set of tables that are "catch all" if you will and have an actual table for fields. In fact I think this may be better as it will allow to add "modules" without much modification to the DB structure. However it would involve larger queries. For example if I want to list all the domains owned by a certain user I need to do a join query to get all fields matching objects of type domain matching the ID of the user.
But should I really be concerned about the speed of my queries these days? Even a bunch of large queries, we're still talking less then 1 second here, and DBs are made for speed and made to be queried. I've always tried to minimize the amount of queries in my programs but I'm wondering if I may be concentrating too hard on that, when I could instead let that slide a tad while maintaining easier to deal with code.
Just wondering how most people approach these things. If it matters, my program is written in C++. I'm only really working at the structure level now, so I want to build a solid foundation and make it super easy to add new modules and if I use my proposed system I will actually be able to add new modules without even modifying the DB, which I think is pretty cool.
Last edited: