Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 2x 2x 3x 2x 3x 4x 9x 1x 1x 3x 2x 2x 2x 2x 2x 1x 5x 6x 3x 3x 1x 1x 1x 1x 1x | import type {
ConfigType,
IBaseDBUpdate,
IDataBase,
PopulatedResult,
QInterfaceSearch,
QueryInterface,
RawQuery,
RawQueryResult,
} from '../lib';
import CoreEntity from './CoreEntity';
import CoreEntityWrapper from './CoreEntityWrapper';
import CoreElement from './CoreElement';
import type {
ColumnPropMap,
EntityConfig,
EUpDateProperties,
IEntity,
} from './annotation';
import CoreDBCon from './CoreDBCon';
/**
* Abstract base class for database prefabs that wrap a CoreDBCon instance.
* <p>
* A prefab encapsulates database operations and entity management while
* providing a unified interface for initializing, updating, and querying
* the underlying database. Concrete subclasses implement {@link initPrefabDB}
* to perform prefab‑specific initialization logic.
*
* @template T The concrete CoreDBCon type that the prefab operates on.
* @extends CoreElement
* @implements IDataBase<unknown, unknown>
*/
export default abstract class CoreDBPrefab<
T extends CoreDBCon<any, any, any, any, any, any, any>,
>
extends CoreElement
implements IDataBase<unknown, unknown>
{
db: T;
constructor(db: T) {
super(`db${db.getModule().getName()}`, db.getModule());
this.db = db;
}
abstract initPrefabDB(): Promise<void>;
getEntityMeta(): { key: string; meta: ColumnPropMap<any> }[] {
return this.db.getEntityMeta();
}
getPrefabDB() {
return this.db;
}
setEntityCache(status: boolean) {
this.db.setEntityCache(status);
}
registerEntity<E extends CoreEntity>(ent: E): CoreEntityWrapper<E> {
return this.db.registerEntity<E>(ent);
}
getEntityWrapper<E extends CoreEntity>(
className: string,
): CoreEntityWrapper<E> {
return this.db.getEntityWrapper<E>(className);
}
setUpdateChain(...chain: IBaseDBUpdate[]): void {
this.db.setUpdateChain(...chain);
}
async canUpdate(): Promise<boolean> {
return this.db.canUpdate();
}
async getCurrenDBVersion(): Promise<string> {
return this.db.getCurrenDBVersion();
}
async update(): Promise<boolean> {
return this.db.update();
}
isConnected(): boolean {
return this.db.isConnected();
}
setConnected(): void {
this.db.setConnected();
}
async start(): Promise<void> {
await this.db.start();
Eif (this.db.getNew()) {
await this.initPrefabDB();
}
}
async disconnect(): Promise<boolean> {
return this.db.disconnect();
}
async connect(): Promise<boolean> {
return this.db.connect();
}
async runScripts(...list: RawQuery[]): Promise<any[]> {
return this.db.runScripts(...list);
}
async queryScript<E>(query: RawQuery): Promise<RawQueryResult<E, any>> {
return this.db.queryScript(query);
}
async getConfig(key: string): Promise<ConfigType | undefined> {
return this.db.getConfig(key);
}
async setConfig(key: string, value: string): Promise<boolean> {
return this.db.setConfig(key, value);
}
async configExist(key: string): Promise<boolean> {
return this.db.configExist(key);
}
async removeConfig(key: string): Promise<void> {
return this.db.removeConfig(key);
}
async getRawDBObject(): Promise<unknown> {
return this.db.getRawDBObject();
}
async initNewDB(): Promise<void> {
await this.db.initNewDB();
await this.initPrefabDB();
}
/**
* Create new Entity object
* @param config
* @param entity
*/
async createEntity<E extends CoreEntity>(
config: EntityConfig<E>,
entity: E,
): Promise<E> {
return this.db.createEntity<E>(config, entity);
}
/**
* Update Entity object
* @param config
* @param e_id
* @param entity
*/
async updateEntity<E extends CoreEntity>(
config: EntityConfig<E>,
e_id: string,
entity: EUpDateProperties<E>,
): Promise<boolean> {
return this.db.updateEntity<E>(config, e_id, entity);
}
/**
* Update Entity objects
* @param config
* @param e_id
* @param entity
*/
async updateBulkEntity<E extends IEntity>(
config: EntityConfig<E>,
e_id: string[],
entity: EUpDateProperties<E>,
): Promise<boolean> {
return this.db.updateBulkEntity(config, e_id, entity);
}
/**
* Get Entity object by ID
* @param config
* @param id
*/
async getEntityById<E extends CoreEntity>(
config: EntityConfig<E>,
id: string,
): Promise<E | null> {
return this.db.getEntityById<E>(config, id);
}
/**
* Get Entity objects by ID
* @param config
* @param id
*/
async getEntityBulkById<E extends CoreEntity>(
config: EntityConfig<E>,
id: string[],
): Promise<E[]> {
return this.db.getEntityBulkById<E>(config, id);
}
/**
* Delete Entity object by ID
* @param className
* @param e_id
*/
async deleteEntityById(className: string, e_id: string): Promise<boolean> {
return this.db.deleteEntityById(className, e_id);
}
/**
* Delete Entity objects by ID
* @param className
* @param e_id
*/
deleteEntityBulkById(className: string, e_id: string[]): Promise<boolean> {
return this.db.deleteEntityBulkById(className, e_id);
}
/**
* Get Entity object list
* @param query
*/
async getEntityList<E extends CoreEntity>(
query: QueryInterface<E>,
): Promise<E[]> {
return this.db.getEntityList<E>(query);
}
/**
* Get Entity object list
* @param config
* @param search
*/
async findEntity<E extends CoreEntity>(
config: EntityConfig<E>,
search: {
[P in keyof E]?: E[P];
},
): Promise<E | null> {
return this.db.findEntity<E>(config, search);
}
/**
* Init Entity object list
* @param className
* @param entity
*/
async initEntity<E extends CoreEntity>(
className: string,
entity: E,
): Promise<boolean> {
return this.db.initEntity<E>(className, entity);
}
countEntity<E extends IEntity>(
config: EntityConfig<E>,
search: QInterfaceSearch<E>,
): Promise<number> {
return this.db.countEntity(config, search);
}
async populate<
E extends CoreEntity,
EK extends keyof E,
R extends CoreEntity,
>(entity: E, field: EK): Promise<PopulatedResult<E, EK, R>> {
return this.db.populate(entity, field);
}
async populateMany<
E extends CoreEntity,
EK extends keyof E,
R extends CoreEntity,
>(entity: E[], field: EK): Promise<PopulatedResult<E, EK, R>[]> {
return this.db.populateMany(entity, field);
}
getCache() {
return this.db.getCache();
}
}
|