Skip to content

Commit 9a85ebb

Browse files
author
Koen Deforche
committed
missing file, and restore (undocumented) split script functionality
1 parent ac09e10 commit 9a85ebb

File tree

4 files changed

+129
-10
lines changed

4 files changed

+129
-10
lines changed

examples/feature/dbo/tutorial6.C

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright (C) 2010 Emweb bvba, Kessel-Lo, Belgium.
3+
*
4+
* See the LICENSE file for terms of use.
5+
*/
6+
7+
/*****
8+
* This file is part of the Wt::Dbo tutorial:
9+
* http://www.webtoolkit.eu/wt/doc/tutorial/dbo/tutorial.html
10+
*****/
11+
12+
/*****
13+
* Dbo tutorial section 7.5
14+
* Specifying a natural primary key that is also a foreign key
15+
*****/
16+
17+
#include <Wt/Dbo/Dbo>
18+
#include <Wt/Dbo/backend/Sqlite3>
19+
20+
namespace dbo = Wt::Dbo;
21+
22+
class UserInfo;
23+
class User;
24+
25+
namespace Wt {
26+
namespace Dbo {
27+
28+
template<>
29+
struct dbo_traits<UserInfo> : public dbo_default_traits {
30+
typedef ptr<User> IdType;
31+
32+
static IdType invalidId() {
33+
return ptr<User>();
34+
}
35+
36+
static const char *surrogateIdField() { return 0; }
37+
};
38+
39+
}
40+
}
41+
42+
class User {
43+
public:
44+
std::string name;
45+
46+
dbo::collection< dbo::ptr<UserInfo> > infos;
47+
48+
template<class Action>
49+
void persist(Action& a)
50+
{
51+
dbo::field(a, name, "name");
52+
53+
// In fact, this is really constrained to hasOne() ...
54+
dbo::hasMany(a, infos, dbo::ManyToOne, "user");
55+
}
56+
};
57+
58+
class UserInfo {
59+
public:
60+
dbo::ptr<User> user;
61+
std::string info;
62+
63+
template<class Action>
64+
void persist(Action& a)
65+
{
66+
dbo::id(a, user, "user", dbo::OnDeleteCascade);
67+
dbo::field(a, info, "info");
68+
}
69+
};
70+
71+
void run()
72+
{
73+
/*
74+
* Setup a session, would typically be done once at application startup.
75+
*/
76+
dbo::backend::Sqlite3 sqlite3(":memory:");
77+
sqlite3.setProperty("show-queries", "true");
78+
dbo::Session session;
79+
session.setConnection(sqlite3);
80+
81+
session.mapClass<User>("user");
82+
session.mapClass<UserInfo>("user_info");
83+
84+
/*
85+
* Try to create the schema (will fail if already exists).
86+
*/
87+
session.createTables();
88+
89+
dbo::Transaction transaction(session);
90+
91+
{
92+
User *user = new User();
93+
user->name = "Joe";
94+
95+
dbo::ptr<User> userPtr = session.add(user);
96+
97+
UserInfo *userInfo = new UserInfo();
98+
userInfo->user = userPtr;
99+
userInfo->info = "great guy";
100+
101+
session.add(userInfo);
102+
103+
transaction.commit();
104+
}
105+
106+
{
107+
dbo::Transaction transaction(session);
108+
109+
dbo::ptr<UserInfo> info = session.find<UserInfo>();
110+
111+
std::cerr << info->user->name << " is a " << info->info << std::endl;
112+
113+
transaction.commit();
114+
}
115+
}
116+
117+
int main(int argc, char **argv)
118+
{
119+
run();
120+
}

src/web/skeleton/Boot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ _$_$if_SPLIT_SCRIPT_$_();
153153
/* Ideally, we should be able to omit the sessionid too */
154154
loadScript(selfUrl + allInfo + '&request=script&skeleton=true',
155155
function() {
156-
loadScript(selfUrl +
156+
loadScript(selfUrl + allInfo
157157
+ '&request=script&rand=' + rand(), null);
158158
});
159159
_$_$endif_$_();

src/web/skeleton/Boot.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wt_config.xml.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,8 @@
232232

233233
Log the response time for each HTTP request or websocket
234234
message (to stderr). This includes the time to parse the
235-
request parameters and body, generate the result, and send
236-
it to the client (so it will depend also on the distance to
237-
the client).
235+
request parameters and body, generate the result, but
236+
excludes time spent in HTTP I/O.
238237
-->
239238
<log-response-time>false</log-response-time>
240239

0 commit comments

Comments
 (0)