HamedMasafi / Nut

Advanced, Powerful and easy to use ORM for Qt
GNU Lesser General Public License v3.0
294 stars 75 forks source link

Ambiguous in doc #26

Closed LinArcX closed 6 years ago

LinArcX commented 6 years ago

Hi. and thank you for this greate job. i want to use nut in my app but i;m a bit confused about docs. see:

Read data from database:

auto q = db.posts()->createQuery();
q->setWhere(Post::idField() == postId);
auto posts = q->toList();
// now posts is a QList<Post*> contain all posts in
//  database that has id equal to postId variable
auto post = q->first();
// post is first row in database that its id is equal to postId

where db defined? or in update sample:

Post *newPost = new Post;
newPost->setTitle("post title");

db.posts()->append(newPost);

for(int i = 0 ; i < 3; i++){
    Comment *comment = new Comment;
    comment->setMessage("comment #" + QString::number(i));

    newPost->comments()->append(comment);
}
db.saveChanges();

The Post Object comes from where?! and how db knows that it has a posts() method?

HamedMasafi commented 6 years ago

Hi

The object db is an instance of Nut::Database-Delivered class. Checkout tests dir for more samples please. https://github.com/HamedMasafi/Nut/blob/master/test/common/weblogdatabase.h

Let me know if you have any other problem

BR

liufeijin commented 5 years ago

Hi

The object db is an instance of Nut::Database-Delivered class. Checkout tests dir for more samples please. https://github.com/HamedMasafi/Nut/blob/master/test/common/weblogdatabase.h

Let me know if you have any other problem

BR

I have a look on weblogdatabase.h and weblogdtabase.cpp, but sitll confused . example i want to connect to a mysql database : source is 192.168.2.1:8987 username: jefftiger password:12345. how can i to do for connecting it? best regards, jeff

HamedMasafi commented 5 years ago

Just like QSqlDatabase

liufeijin commented 5 years ago

we normal use QSqlDatabase as below codes: QSqlDatabase dbx = QSqlDatabase::addDatabase("QMYSQL","xgmm"); dbx.setHostName("db-dskvg072.sql.otto.com"); dbx.setPort(62795); dbx.setDatabaseName("test"); dbx.setUserName(LUserName); dbx.setPassword(LUserPW);

but i don't know how to use it in weblogdatabase.h cloud you give me a simple code? best regards, jeff

HamedMasafi commented 5 years ago
WeblogDatabase dbx;
dbx.setDriver("QMYSQL");
dbx.setHostName("db-dskvg072.sql.otto.com");
dbx.setPort(62795);
dbx.setDatabaseName("test");
dbx.setUserName(LUserName);
dbx.setPassword(LUserPW);
liufeijin commented 5 years ago

hi Many thanks for your explain. i will have a try. best regards, jeff

liufeijin commented 5 years ago
WeblogDatabase dbx;
dbx.setDriver("QMYSQL");
dbx.setHostName("db-dskvg072.sql.otto.com");
dbx.setPort(62795);
dbx.setDatabaseName("test");
dbx.setUserName(LUserName);
dbx.setPassword(LUserPW);
qDebug()<<dbx.open();

hi HamedMasafi I have a try. the error is still QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 Could not connect to database, error = Driver not loaded Driver not loaded false Anything is wrong in my code? Nut seems need mysql driver still and not is a depend third part drivers?