design - Challenge - Keep Code and DB Rows Separate -


We all agree that DB is for storage and this code should not be tightly coupled with it. Give me an example of how you can get it when you store preferences in DB.

Suppose you are creating a little online survey. There are some vote types in each poll:

  • anonymous voting
  • IP based voting
  • etc.

Now if there is an interface where a user creates a poll and stores the "vote type", it seems that at some point you can use DB (either the primary key or a Name), which does' anonymous voting ', IP based voting' etc.

In a different but related, John Sanders said that it is silly - and I agree with him completely! Why connect db and code - this is a bad idea but how do you avoid it if you are accumulating something like "vote type"?

Just define some constellations, whether they are in an enum or whatever supports your language Are, e.g.

In the database with a vote type column value value in the database with continuous enum vototype {ANON = 1, IP = 2, ...}

. If you want to apply the relevance of the integrity referenced in your database, make a lookup table with the relevant value, otherwise it is just an opaque piece of data for the database.

There is no coupling in comparison to the pole table, titled, Title, Title. This is an aspect of the choice you have stored, so store it.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -