What the best way to store data in Model?

Hi all!
I'm a php developer with 7 yeas experience.
I know a little c++\qt, but i need some help.
I want to combine some libraries like: pqxx, jsoncpp.
It will be a new comercial product and I don't want to use any frameworks like: CppCms or Wt++ i.e. They will be impose restrictions to my app.
The application will be a simple JSON RESTsever.
I have a good knowledge about MVC pradigm, but only in php.
And my question is: What the best way to store data in models getting them form database?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//For example(on PHP):
class User extends ActiveRecord{
   public $username;
   public $password;
//i.t.e.
}

$user = User::findOne();

//I don't need to care about HOW the data will be assigning to fields in the object of class. What about c++? How to realize a similar? Is it must be a member of the class or some array of Varian type or string;

//I have some designs. For example (on c++):
class User{
  protected:
   string username;
   string password;

  public:
   void findOne(){
     //The DB for example only, not real code! 
     this.username = DB.get("username");
     this.password = DB.get("password");
   }
} 

//OR THIS?
class User{
  protected:
   string fields[2];

  public:
   void findOne(){
     //The DB for example only, not real code! 
     this->fields[0] = DB.get("username");
     this->fields[1] = DB.get("password");
   }
} 

//what the best way? Maybe it be must a factory? I don't know. Help me plz! 
Last edited on
I tried the Json::Value. This is cool storage.
Shouldn't actually the model be responsible to get and set values in the database ?
So you would have one class User, a class UserModel and a class Database where UserModel deals with the user data. If you want to change from a database to a json or xml file you only need to change the UserModel, but not User class.
Topic archived. No new replies allowed.