| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import { Constraints, Field, FieldType, IEntity } from "../DbConnector/Query";
- const TABLE_NAME = "apiKey";
- export default class ApiKeyModel implements IEntity {
- public FromDb(dbObj: Map<string, string>): ApiKeyModel {
- this.mUserId = parseInt(dbObj.get(ApiKeyModel.USERID.mName) || "0", 10) || ApiKeyModel.USERID.mDefault;
- this.mKey = dbObj.get(ApiKeyModel.KEY.mName) || ApiKeyModel.KEY.mDefault;
- this.mComment = dbObj.get(ApiKeyModel.COMMENT.mName) || ApiKeyModel.COMMENT.mDefault;
- return this;
- }
- public ToDb(): Map<string, string> {
- let result = new Map();
- result.set(ApiKeyModel.USERID.mName, this.mUserId);
- result.set(ApiKeyModel.KEY.mName, this.mKey);
- result.set(ApiKeyModel.COMMENT.mName, this.mComment);
- return result;
- }
- public GetUserId(): number {
- return this.mUserId;
- }
- public GetTableName() {
- return TABLE_NAME;
- }
- public GetTableFields() {
- return [ApiKeyModel.USERID, ApiKeyModel.KEY, ApiKeyModel.COMMENT];
- }
- public GetTableConstraints() {
- let result = new Constraints();
- result.mPrimaryKeys = [ApiKeyModel.KEY];
- result.pushUniqueFields([ApiKeyModel.USERID, ApiKeyModel.COMMENT]);
- return result;
- }
- private mUserId: number =0;
- private mKey: string = "";
- private mComment: string = "";
- public static readonly USERID: Field<number> = new Field<number>(TABLE_NAME, "userid", FieldType.eNumber, 0, false, 16);
- public static readonly KEY: Field<string> = new Field<string>(TABLE_NAME, "key", FieldType.eString, "", false, 256);
- public static readonly COMMENT: Field<string> = new Field<string>(TABLE_NAME, "comment", FieldType.eString, "", false, 256);
- }
|