File: Users.h

package info (click to toggle)
drogon 1.9.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,096 kB
  • sloc: cpp: 52,222; sh: 249; xml: 20; makefile: 11
file content (406 lines) | stat: -rw-r--r-- 13,829 bytes parent folder | download
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/**
 *
 *  Users.h
 *  DO NOT EDIT. This file is generated by drogon_ctl
 *
 */

#pragma once
#include <drogon/orm/Result.h>
#include <drogon/orm/Row.h>
#include <drogon/orm/Field.h>
#include <drogon/orm/SqlBinder.h>
#include <drogon/orm/Mapper.h>
#include <drogon/orm/BaseBuilder.h>
#ifdef __cpp_impl_coroutine
#include <drogon/orm/CoroMapper.h>
#endif
#include <trantor/utils/Date.h>
#include <trantor/utils/Logger.h>
#include <json/json.h>
#include <string>
#include <memory>
#include <vector>
#include <tuple>
#include <stdint.h>
#include <iostream>

namespace drogon
{
namespace orm
{
class DbClient;
using DbClientPtr = std::shared_ptr<DbClient>;
}  // namespace orm
}  // namespace drogon

namespace drogon_model
{
namespace sqlite3
{
class Users
{
  public:
    struct Cols
    {
        static const std::string _id;
        static const std::string _user_id;
        static const std::string _user_name;
        static const std::string _password;
        static const std::string _org_name;
        static const std::string _signature;
        static const std::string _avatar_id;
        static const std::string _salt;
        static const std::string _admin;
        static const std::string _create_time;
    };

    const static int primaryKeyNumber;
    const static std::string tableName;
    const static bool hasPrimaryKey;
    const static std::string primaryKeyName;
    using PrimaryKeyType = uint64_t;
    const PrimaryKeyType &getPrimaryKey() const;

    /**
     * @brief constructor
     * @param r One row of records in the SQL query result.
     * @param indexOffset Set the offset to -1 to access all columns by column
     * names, otherwise access all columns by offsets.
     * @note If the SQL is not a style of 'select * from table_name ...' (select
     * all columns by an asterisk), please set the offset to -1.
     */
    explicit Users(const drogon::orm::Row &r,
                   const ssize_t indexOffset = 0) noexcept;

    /**
     * @brief constructor
     * @param pJson The json object to construct a new instance.
     */
    explicit Users(const Json::Value &pJson) noexcept(false);

    /**
     * @brief constructor
     * @param pJson The json object to construct a new instance.
     * @param pMasqueradingVector The aliases of table columns.
     */
    Users(const Json::Value &pJson,
          const std::vector<std::string> &pMasqueradingVector) noexcept(false);

    Users() = default;

    void updateByJson(const Json::Value &pJson) noexcept(false);
    void updateByMasqueradedJson(
        const Json::Value &pJson,
        const std::vector<std::string> &pMasqueradingVector) noexcept(false);
    static bool validateJsonForCreation(const Json::Value &pJson,
                                        std::string &err);
    static bool validateMasqueradedJsonForCreation(
        const Json::Value &,
        const std::vector<std::string> &pMasqueradingVector,
        std::string &err);
    static bool validateJsonForUpdate(const Json::Value &pJson,
                                      std::string &err);
    static bool validateMasqueradedJsonForUpdate(
        const Json::Value &,
        const std::vector<std::string> &pMasqueradingVector,
        std::string &err);
    static bool validJsonOfField(size_t index,
                                 const std::string &fieldName,
                                 const Json::Value &pJson,
                                 std::string &err,
                                 bool isForCreation);

    /**  For column id  */
    /// Get the value of the column id, returns the default value if the column
    /// is null
    const uint64_t &getValueOfId() const noexcept;
    /// Return a shared_ptr object pointing to the column const value, or an
    /// empty shared_ptr object if the column is null
    const std::shared_ptr<uint64_t> &getId() const noexcept;
    /// Set the value of the column id
    void setId(const uint64_t &pId) noexcept;
    void setIdToNull() noexcept;

    /**  For column user_id  */
    /// Get the value of the column user_id, returns the default value if the
    /// column is null
    const std::string &getValueOfUserId() const noexcept;
    /// Return a shared_ptr object pointing to the column const value, or an
    /// empty shared_ptr object if the column is null
    const std::shared_ptr<std::string> &getUserId() const noexcept;
    /// Set the value of the column user_id
    void setUserId(const std::string &pUserId) noexcept;
    void setUserId(std::string &&pUserId) noexcept;
    void setUserIdToNull() noexcept;

    /**  For column user_name  */
    /// Get the value of the column user_name, returns the default value if the
    /// column is null
    const std::string &getValueOfUserName() const noexcept;
    /// Return a shared_ptr object pointing to the column const value, or an
    /// empty shared_ptr object if the column is null
    const std::shared_ptr<std::string> &getUserName() const noexcept;
    /// Set the value of the column user_name
    void setUserName(const std::string &pUserName) noexcept;
    void setUserName(std::string &&pUserName) noexcept;
    void setUserNameToNull() noexcept;

    /**  For column password  */
    /// Get the value of the column password, returns the default value if the
    /// column is null
    const std::string &getValueOfPassword() const noexcept;
    /// Return a shared_ptr object pointing to the column const value, or an
    /// empty shared_ptr object if the column is null
    const std::shared_ptr<std::string> &getPassword() const noexcept;
    /// Set the value of the column password
    void setPassword(const std::string &pPassword) noexcept;
    void setPassword(std::string &&pPassword) noexcept;
    void setPasswordToNull() noexcept;

    /**  For column org_name  */
    /// Get the value of the column org_name, returns the default value if the
    /// column is null
    const std::string &getValueOfOrgName() const noexcept;
    /// Return a shared_ptr object pointing to the column const value, or an
    /// empty shared_ptr object if the column is null
    const std::shared_ptr<std::string> &getOrgName() const noexcept;
    /// Set the value of the column org_name
    void setOrgName(const std::string &pOrgName) noexcept;
    void setOrgName(std::string &&pOrgName) noexcept;
    void setOrgNameToNull() noexcept;

    /**  For column signature  */
    /// Get the value of the column signature, returns the default value if the
    /// column is null
    const std::string &getValueOfSignature() const noexcept;
    /// Return a shared_ptr object pointing to the column const value, or an
    /// empty shared_ptr object if the column is null
    const std::shared_ptr<std::string> &getSignature() const noexcept;
    /// Set the value of the column signature
    void setSignature(const std::string &pSignature) noexcept;
    void setSignature(std::string &&pSignature) noexcept;
    void setSignatureToNull() noexcept;

    /**  For column avatar_id  */
    /// Get the value of the column avatar_id, returns the default value if the
    /// column is null
    const std::string &getValueOfAvatarId() const noexcept;
    /// Return a shared_ptr object pointing to the column const value, or an
    /// empty shared_ptr object if the column is null
    const std::shared_ptr<std::string> &getAvatarId() const noexcept;
    /// Set the value of the column avatar_id
    void setAvatarId(const std::string &pAvatarId) noexcept;
    void setAvatarId(std::string &&pAvatarId) noexcept;
    void setAvatarIdToNull() noexcept;

    /**  For column salt  */
    /// Get the value of the column salt, returns the default value if the
    /// column is null
    const std::string &getValueOfSalt() const noexcept;
    /// Return a shared_ptr object pointing to the column const value, or an
    /// empty shared_ptr object if the column is null
    const std::shared_ptr<std::string> &getSalt() const noexcept;
    /// Set the value of the column salt
    void setSalt(const std::string &pSalt) noexcept;
    void setSalt(std::string &&pSalt) noexcept;
    void setSaltToNull() noexcept;

    /**  For column admin  */
    /// Get the value of the column admin, returns the default value if the
    /// column is null
    const std::string &getValueOfAdmin() const noexcept;
    /// Return a shared_ptr object pointing to the column const value, or an
    /// empty shared_ptr object if the column is null
    const std::shared_ptr<std::string> &getAdmin() const noexcept;
    /// Set the value of the column admin
    void setAdmin(const std::string &pAdmin) noexcept;
    void setAdmin(std::string &&pAdmin) noexcept;
    void setAdminToNull() noexcept;

    /**  For column create_time  */
    /// Get the value of the column create_time, returns the default value if
    /// the column is null
    const ::trantor::Date &getValueOfCreateTime() const noexcept;
    /// Return a shared_ptr object pointing to the column const value, or an
    /// empty shared_ptr object if the column is null
    const std::shared_ptr<::trantor::Date> &getCreateTime() const noexcept;
    /// Set the value of the column create_time
    void setCreateTime(const ::trantor::Date &pCreateTime) noexcept;
    void setCreateTimeToNull() noexcept;

    static size_t getColumnNumber() noexcept
    {
        return 10;
    }

    static const std::string &getColumnName(size_t index) noexcept(false);

    Json::Value toJson() const;
    Json::Value toMasqueradedJson(
        const std::vector<std::string> &pMasqueradingVector) const;
    /// Relationship interfaces
  private:
    friend drogon::orm::Mapper<Users>;
    friend drogon::orm::BaseBuilder<Users, true, true>;
    friend drogon::orm::BaseBuilder<Users, true, false>;
    friend drogon::orm::BaseBuilder<Users, false, true>;
    friend drogon::orm::BaseBuilder<Users, false, false>;
#ifdef __cpp_impl_coroutine
    friend drogon::orm::CoroMapper<Users>;
#endif
    static const std::vector<std::string> &insertColumns() noexcept;
    void outputArgs(drogon::orm::internal::SqlBinder &binder) const;
    const std::vector<std::string> updateColumns() const;
    void updateArgs(drogon::orm::internal::SqlBinder &binder) const;
    /// For mysql or sqlite3
    void updateId(const uint64_t id);
    std::shared_ptr<uint64_t> id_;
    std::shared_ptr<std::string> userId_;
    std::shared_ptr<std::string> userName_;
    std::shared_ptr<std::string> password_;
    std::shared_ptr<std::string> orgName_;
    std::shared_ptr<std::string> signature_;
    std::shared_ptr<std::string> avatarId_;
    std::shared_ptr<std::string> salt_;
    std::shared_ptr<std::string> admin_;
    std::shared_ptr<::trantor::Date> createTime_;

    struct MetaData
    {
        const std::string colName_;
        const std::string colType_;
        const std::string colDatabaseType_;
        const ssize_t colLength_;
        const bool isAutoVal_;
        const bool isPrimaryKey_;
        const bool notNull_;
    };

    static const std::vector<MetaData> metaData_;
    bool dirtyFlag_[10] = {false};

  public:
    static const std::string &sqlForFindingByPrimaryKey()
    {
        static const std::string sql =
            "select * from " + tableName + " where id = ?";
        return sql;
    }

    static const std::string &sqlForDeletingByPrimaryKey()
    {
        static const std::string sql =
            "delete from " + tableName + " where id = ?";
        return sql;
    }

    std::string sqlForInserting(bool &needSelection) const
    {
        std::string sql = "insert into " + tableName + " (";
        size_t parametersCount = 0;
        needSelection = false;
        if (dirtyFlag_[1])
        {
            sql += "user_id,";
            ++parametersCount;
        }
        if (dirtyFlag_[2])
        {
            sql += "user_name,";
            ++parametersCount;
        }
        if (dirtyFlag_[3])
        {
            sql += "password,";
            ++parametersCount;
        }
        if (dirtyFlag_[4])
        {
            sql += "org_name,";
            ++parametersCount;
        }
        if (dirtyFlag_[5])
        {
            sql += "signature,";
            ++parametersCount;
        }
        if (dirtyFlag_[6])
        {
            sql += "avatar_id,";
            ++parametersCount;
        }
        if (dirtyFlag_[7])
        {
            sql += "salt,";
            ++parametersCount;
        }
        if (dirtyFlag_[8])
        {
            sql += "admin,";
            ++parametersCount;
        }
        if (!dirtyFlag_[8])
        {
            needSelection = true;
        }
        if (dirtyFlag_[9])
        {
            sql += "create_time,";
            ++parametersCount;
        }
        if (parametersCount > 0)
        {
            sql[sql.length() - 1] = ')';
            sql += " values (";
        }
        else
            sql += ") values (";

        if (dirtyFlag_[1])
        {
            sql.append("?,");
        }
        if (dirtyFlag_[2])
        {
            sql.append("?,");
        }
        if (dirtyFlag_[3])
        {
            sql.append("?,");
        }
        if (dirtyFlag_[4])
        {
            sql.append("?,");
        }
        if (dirtyFlag_[5])
        {
            sql.append("?,");
        }
        if (dirtyFlag_[6])
        {
            sql.append("?,");
        }
        if (dirtyFlag_[7])
        {
            sql.append("?,");
        }
        if (dirtyFlag_[8])
        {
            sql.append("?,");
        }
        if (dirtyFlag_[9])
        {
            sql.append("?,");
        }
        if (parametersCount > 0)
        {
            sql.resize(sql.length() - 1);
        }
        sql.append(1, ')');
        LOG_TRACE << sql;
        return sql;
    }
};
}  // namespace sqlite3
}  // namespace drogon_model