@onurege3467/zerohelper 8.0.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +292 -612
- package/dist/database/IDatabase.d.ts +77 -0
- package/dist/database/IDatabase.js +10 -0
- package/dist/database/cacheWrapper.d.ts +31 -0
- package/dist/database/cacheWrapper.js +228 -0
- package/dist/database/index.d.ts +11 -0
- package/dist/database/index.js +94 -0
- package/dist/database/json.d.ts +32 -0
- package/dist/database/json.js +210 -0
- package/dist/database/migration.d.ts +21 -0
- package/dist/database/migration.js +97 -0
- package/dist/database/mongodb.d.ts +24 -0
- package/dist/database/mongodb.js +153 -0
- package/dist/database/mysql.d.ts +31 -0
- package/dist/database/mysql.js +385 -0
- package/dist/database/pg.d.ts +30 -0
- package/dist/database/pg.js +300 -0
- package/dist/database/redis.d.ts +23 -0
- package/dist/database/redis.js +157 -0
- package/dist/database/sqlite.d.ts +25 -0
- package/dist/database/sqlite.js +273 -0
- package/dist/database/types.d.ts +76 -0
- package/dist/database/types.js +2 -0
- package/dist/database/zpack.d.ts +59 -0
- package/dist/database/zpack.js +462 -0
- package/dist/functions/index.d.ts +183 -0
- package/dist/functions/index.js +636 -0
- package/dist/functions/temp_isphone.d.ts +1 -0
- package/dist/functions/temp_isphone.js +7 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +45 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +55 -0
- package/dist/test_zpack.d.ts +1 -0
- package/dist/test_zpack.js +64 -0
- package/package.json +23 -6
- package/database/IDatabase.js +0 -92
- package/database/cacheWrapper.js +0 -585
- package/database/index.js +0 -72
- package/database/json.js +0 -281
- package/database/migration.js +0 -227
- package/database/mongodb.js +0 -203
- package/database/mysql.js +0 -526
- package/database/pg.js +0 -527
- package/database/redis.js +0 -342
- package/database/sqlite.js +0 -551
- package/functions/index.js +0 -705
- package/index.js +0 -7
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tüm veritabanı adaptörlerinin uyması gereken ortak arayüzü tanımlar.
|
|
3
|
+
*/
|
|
4
|
+
export declare abstract class IDatabase {
|
|
5
|
+
/**
|
|
6
|
+
* Belirtilen koşullara göre birden çok kayıt seçer.
|
|
7
|
+
* @param table - Verinin seçileceği tablo veya koleksiyonun adı.
|
|
8
|
+
* @param where - (Opsiyonel) Kayıtları filtrelemek için kullanılacak koşul nesnesi.
|
|
9
|
+
* @returns Koşullara uyan kayıtların bir dizisini içeren bir Promise.
|
|
10
|
+
*/
|
|
11
|
+
abstract select<T = any>(table: string, where?: Record<string, any> | null): Promise<T[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Belirtilen koşullara göre tek bir kayıt seçer.
|
|
14
|
+
* @param table - Verinin seçileceği tablo veya koleksiyonun adı.
|
|
15
|
+
* @param where - (Opsiyonel) Kaydı filtrelemek için kullanılacak koşul nesnesi.
|
|
16
|
+
* @returns Koşula uyan ilk kaydı veya bulunamazsa `null` içeren bir Promise.
|
|
17
|
+
*/
|
|
18
|
+
abstract selectOne<T = any>(table: string, where?: Record<string, any> | null): Promise<T | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Yeni bir kayıt ekler.
|
|
21
|
+
* @param table - Verinin ekleneceği tablo veya koleksiyonun adı.
|
|
22
|
+
* @param data - Eklenecek veriyi içeren nesne.
|
|
23
|
+
* @returns Eklenen yeni kaydın ID'sini içeren bir Promise.
|
|
24
|
+
*/
|
|
25
|
+
abstract insert(table: string, data: Record<string, any>): Promise<number | string | any>;
|
|
26
|
+
/**
|
|
27
|
+
* Belirtilen koşullara uyan kayıtları günceller.
|
|
28
|
+
* @param table - Verinin güncelleneceği tablo veya koleksiyonun adı.
|
|
29
|
+
* @param data - Güncellenecek yeni verileri içeren nesne.
|
|
30
|
+
* @param where - Hangi kayıtların güncelleneceğini belirleyen koşul nesnesi.
|
|
31
|
+
* @returns Etkilenen (güncellenen) kayıt sayısını içeren bir Promise.
|
|
32
|
+
*/
|
|
33
|
+
abstract update(table: string, data: Record<string, any>, where: Record<string, any>): Promise<number>;
|
|
34
|
+
/**
|
|
35
|
+
* Bir kaydı günceller veya yoksa yeni bir kayıt olarak ekler (Upsert).
|
|
36
|
+
* @param table - İşlem yapılacak tablo veya koleksiyonun adı.
|
|
37
|
+
* @param data - Ayarlanacak veya güncellenecek veriyi içeren nesne.
|
|
38
|
+
* @param where - Kaydın varlığını kontrol etmek ve güncellemek için kullanılacak koşul nesnesi.
|
|
39
|
+
* @returns Ekleme durumunda yeni ID'yi, güncelleme durumunda etkilenen satır sayısını içeren bir Promise.
|
|
40
|
+
*/
|
|
41
|
+
abstract set(table: string, data: Record<string, any>, where: Record<string, any>): Promise<any>;
|
|
42
|
+
/**
|
|
43
|
+
* Belirtilen koşullara uyan kayıtları siler.
|
|
44
|
+
* @param table - Verinin silineceği tablo veya koleksiyonun adı.
|
|
45
|
+
* @param where - Hangi kayıtların silineceğini belirleyen koşul nesnesi.
|
|
46
|
+
* @returns Silinen kayıt sayısını içeren bir Promise.
|
|
47
|
+
*/
|
|
48
|
+
abstract delete(table: string, where: Record<string, any>): Promise<number>;
|
|
49
|
+
/**
|
|
50
|
+
* Birden çok kaydı toplu olarak ekler.
|
|
51
|
+
* @param table - Verilerin ekleneceği tablo veya koleksiyonun adı.
|
|
52
|
+
* @param dataArray - Eklenecek kayıtları içeren bir dizi.
|
|
53
|
+
* @returns Eklenen kayıt sayısını içeren bir Promise.
|
|
54
|
+
*/
|
|
55
|
+
abstract bulkInsert(table: string, dataArray: Record<string, any>[]): Promise<number>;
|
|
56
|
+
/**
|
|
57
|
+
* Numerik alanları artırır (increment).
|
|
58
|
+
* @param table - Verinin güncelleneceği tablo veya koleksiyonun adı.
|
|
59
|
+
* @param increments - Artırılacak alanlar ve miktarları (örn: { views: 1, likes: 2 }).
|
|
60
|
+
* @param where - Hangi kayıtların güncelleneceğini belirleyen koşul nesnesi.
|
|
61
|
+
* @returns Etkilenen kayıt sayısını içeren bir Promise.
|
|
62
|
+
*/
|
|
63
|
+
abstract increment(table: string, increments: Record<string, number>, where: Record<string, any>): Promise<number>;
|
|
64
|
+
/**
|
|
65
|
+
* Numerik alanları azaltır (decrement).
|
|
66
|
+
* @param table - Verinin güncelleneceği tablo veya koleksiyonun adı.
|
|
67
|
+
* @param decrements - Azaltılacak alanlar ve miktarları (örn: { stock: 1, count: 5 }).
|
|
68
|
+
* @param where - Hangi kayıtların güncelleneceğini belirleyen koşul nesnesi.
|
|
69
|
+
* @returns Etkilenen kayıt sayısını içeren bir Promise.
|
|
70
|
+
*/
|
|
71
|
+
abstract decrement(table: string, decrements: Record<string, number>, where: Record<string, any>): Promise<number>;
|
|
72
|
+
/**
|
|
73
|
+
* Veritabanı bağlantısını güvenli bir şekilde sonlandırır.
|
|
74
|
+
*/
|
|
75
|
+
abstract close(): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
export default IDatabase;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IDatabase = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Tüm veritabanı adaptörlerinin uyması gereken ortak arayüzü tanımlar.
|
|
6
|
+
*/
|
|
7
|
+
class IDatabase {
|
|
8
|
+
}
|
|
9
|
+
exports.IDatabase = IDatabase;
|
|
10
|
+
exports.default = IDatabase;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IDatabase } from './IDatabase';
|
|
2
|
+
export declare class CacheWrapper extends IDatabase {
|
|
3
|
+
db: IDatabase;
|
|
4
|
+
private cacheType;
|
|
5
|
+
private tableCaches;
|
|
6
|
+
private redisClient;
|
|
7
|
+
private redisAvailable;
|
|
8
|
+
private ttl;
|
|
9
|
+
private keyPrefix;
|
|
10
|
+
private cache;
|
|
11
|
+
constructor(databaseInstance: IDatabase, options?: any);
|
|
12
|
+
private _initMemoryCache;
|
|
13
|
+
private _initRedisCache;
|
|
14
|
+
private _getCache;
|
|
15
|
+
private _generateKey;
|
|
16
|
+
private _getCacheValue;
|
|
17
|
+
private _setCacheValue;
|
|
18
|
+
private _clearCache;
|
|
19
|
+
private _updateCacheByWhere;
|
|
20
|
+
select<T = any>(table: string, where?: Record<string, any> | null): Promise<T[]>;
|
|
21
|
+
selectOne<T = any>(table: string, where?: Record<string, any> | null): Promise<T | null>;
|
|
22
|
+
insert(table: string, data: Record<string, any>): Promise<any>;
|
|
23
|
+
update(table: string, data: Record<string, any>, where: Record<string, any>): Promise<number>;
|
|
24
|
+
set(table: string, data: Record<string, any>, where: Record<string, any>): Promise<any>;
|
|
25
|
+
delete(table: string, where: Record<string, any>): Promise<number>;
|
|
26
|
+
bulkInsert(table: string, dataArray: Record<string, any>[]): Promise<number>;
|
|
27
|
+
increment(table: string, increments: Record<string, number>, where?: Record<string, any>): Promise<number>;
|
|
28
|
+
decrement(table: string, decrements: Record<string, number>, where?: Record<string, any>): Promise<number>;
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export default CacheWrapper;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheWrapper = void 0;
|
|
4
|
+
const IDatabase_1 = require("./IDatabase");
|
|
5
|
+
const lru_cache_1 = require("lru-cache");
|
|
6
|
+
const redis_1 = require("redis");
|
|
7
|
+
class CacheWrapper extends IDatabase_1.IDatabase {
|
|
8
|
+
constructor(databaseInstance, options = {}) {
|
|
9
|
+
super();
|
|
10
|
+
this.tableCaches = {};
|
|
11
|
+
this.redisClient = null;
|
|
12
|
+
this.redisAvailable = false;
|
|
13
|
+
this.ttl = 300;
|
|
14
|
+
this.keyPrefix = 'db_cache:';
|
|
15
|
+
this.cache = null;
|
|
16
|
+
this.db = databaseInstance;
|
|
17
|
+
this.cacheType = options.type || 'memory';
|
|
18
|
+
if (this.cacheType === 'redis') {
|
|
19
|
+
this._initRedisCache(options);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this._initMemoryCache(options);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
_initMemoryCache(options) {
|
|
26
|
+
this.cache = new lru_cache_1.LRUCache({
|
|
27
|
+
max: options.max || 500,
|
|
28
|
+
ttl: options.ttl || 1000 * 60 * 5,
|
|
29
|
+
});
|
|
30
|
+
this.redisAvailable = false;
|
|
31
|
+
}
|
|
32
|
+
async _initRedisCache(options) {
|
|
33
|
+
const redisConfig = {
|
|
34
|
+
socket: {
|
|
35
|
+
host: options.host || '127.0.0.1',
|
|
36
|
+
port: options.port || 6379,
|
|
37
|
+
connectTimeout: options.connectTimeout || 5000,
|
|
38
|
+
},
|
|
39
|
+
password: options.password,
|
|
40
|
+
database: options.db || 0,
|
|
41
|
+
};
|
|
42
|
+
this.redisClient = (0, redis_1.createClient)(redisConfig);
|
|
43
|
+
this.ttl = (options.ttl || 300000) / 1000;
|
|
44
|
+
this.keyPrefix = options.keyPrefix || 'db_cache:';
|
|
45
|
+
this.redisClient.on('error', (err) => {
|
|
46
|
+
this.redisAvailable = false;
|
|
47
|
+
});
|
|
48
|
+
this.redisClient.on('ready', () => {
|
|
49
|
+
this.redisAvailable = true;
|
|
50
|
+
});
|
|
51
|
+
try {
|
|
52
|
+
await this.redisClient.connect();
|
|
53
|
+
this.redisAvailable = true;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
this._initMemoryCache(options);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
_getCache(table) {
|
|
60
|
+
if (this.cacheType === 'redis' && this.redisAvailable && this.redisClient)
|
|
61
|
+
return this.redisClient;
|
|
62
|
+
if (!this.tableCaches[table]) {
|
|
63
|
+
this.tableCaches[table] = new lru_cache_1.LRUCache({
|
|
64
|
+
max: this.cache?.max || 500,
|
|
65
|
+
ttl: this.cache?.ttl || 300000,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return this.tableCaches[table];
|
|
69
|
+
}
|
|
70
|
+
_generateKey(table, where) {
|
|
71
|
+
const sortedWhere = where ? Object.keys(where).sort().reduce((acc, key) => {
|
|
72
|
+
acc[key] = where[key];
|
|
73
|
+
return acc;
|
|
74
|
+
}, {}) : {};
|
|
75
|
+
const key = `${table}:${JSON.stringify(sortedWhere)}`;
|
|
76
|
+
return this.cacheType === 'redis' ? `${this.keyPrefix}${key}` : key;
|
|
77
|
+
}
|
|
78
|
+
async _getCacheValue(cache, key, table) {
|
|
79
|
+
if (this.cacheType === 'redis' && this.redisAvailable && this.redisClient) {
|
|
80
|
+
try {
|
|
81
|
+
const value = await cache.get(key);
|
|
82
|
+
return value ? JSON.parse(value) : null;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
this.redisAvailable = false;
|
|
86
|
+
return this._getCache(table).get(key);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return cache.get(key);
|
|
90
|
+
}
|
|
91
|
+
async _setCacheValue(cache, key, value, table) {
|
|
92
|
+
if (this.cacheType === 'redis' && this.redisAvailable && this.redisClient) {
|
|
93
|
+
try {
|
|
94
|
+
await cache.setEx(key, Math.floor(this.ttl), JSON.stringify(value));
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
this.redisAvailable = false;
|
|
98
|
+
this._getCache(table).set(key, value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
cache.set(key, value);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async _clearCache(table) {
|
|
106
|
+
if (this.cacheType === 'redis' && this.redisAvailable && this.redisClient) {
|
|
107
|
+
try {
|
|
108
|
+
const keys = await this.redisClient.keys(`${this.keyPrefix}${table}:*`);
|
|
109
|
+
if (keys.length)
|
|
110
|
+
await this.redisClient.del(keys);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
this.redisAvailable = false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (this.tableCaches[table])
|
|
117
|
+
this.tableCaches[table].clear();
|
|
118
|
+
}
|
|
119
|
+
async _updateCacheByWhere(table, where, newData = null) {
|
|
120
|
+
if (!where || Object.keys(where).length === 0) {
|
|
121
|
+
await this._clearCache(table);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (this.cacheType === 'redis' && this.redisAvailable && this.redisClient) {
|
|
125
|
+
try {
|
|
126
|
+
const keys = await this.redisClient.keys(`${this.keyPrefix}${table}:*`);
|
|
127
|
+
for (const fullKey of keys) {
|
|
128
|
+
const cacheData = await this.redisClient.get(fullKey);
|
|
129
|
+
if (cacheData) {
|
|
130
|
+
const parsedData = JSON.parse(cacheData);
|
|
131
|
+
if (Object.entries(where).every(([k, v]) => parsedData[k] === v)) {
|
|
132
|
+
if (newData)
|
|
133
|
+
await this.redisClient.setEx(fullKey, Math.floor(this.ttl), JSON.stringify(newData));
|
|
134
|
+
else
|
|
135
|
+
await this.redisClient.del(fullKey);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
await this._clearCache(table);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const cache = this._getCache(table);
|
|
145
|
+
if (cache instanceof lru_cache_1.LRUCache) {
|
|
146
|
+
const keysToDelete = [];
|
|
147
|
+
cache.forEach((value, key) => {
|
|
148
|
+
if (Object.entries(where).every(([k, v]) => value[k] === v)) {
|
|
149
|
+
if (newData)
|
|
150
|
+
cache.set(key, newData);
|
|
151
|
+
else
|
|
152
|
+
keysToDelete.push(key);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
keysToDelete.forEach(k => cache.delete(k));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async select(table, where = null) {
|
|
159
|
+
const cache = this._getCache(table);
|
|
160
|
+
const key = this._generateKey(table, where);
|
|
161
|
+
let data = await this._getCacheValue(cache, key, table);
|
|
162
|
+
if (data !== null && data !== undefined)
|
|
163
|
+
return data;
|
|
164
|
+
data = await this.db.select(table, where);
|
|
165
|
+
if (data !== null && data !== undefined)
|
|
166
|
+
await this._setCacheValue(cache, key, data, table);
|
|
167
|
+
return data;
|
|
168
|
+
}
|
|
169
|
+
async selectOne(table, where = null) {
|
|
170
|
+
const cache = this._getCache(table);
|
|
171
|
+
const key = this._generateKey(table + '_one', where);
|
|
172
|
+
let data = await this._getCacheValue(cache, key, table);
|
|
173
|
+
if (data !== null && data !== undefined)
|
|
174
|
+
return data;
|
|
175
|
+
data = await this.db.selectOne(table, where);
|
|
176
|
+
if (data !== null && data !== undefined)
|
|
177
|
+
await this._setCacheValue(cache, key, data, table);
|
|
178
|
+
return data;
|
|
179
|
+
}
|
|
180
|
+
async insert(table, data) {
|
|
181
|
+
const result = await this.db.insert(table, data);
|
|
182
|
+
await this._clearCache(table);
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
async update(table, data, where) {
|
|
186
|
+
const result = await this.db.update(table, data, where);
|
|
187
|
+
if (result > 0)
|
|
188
|
+
await this._updateCacheByWhere(table, where, null);
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
async set(table, data, where) {
|
|
192
|
+
const result = await this.db.set(table, data, where);
|
|
193
|
+
await this._updateCacheByWhere(table, where, null);
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
async delete(table, where) {
|
|
197
|
+
const result = await this.db.delete(table, where);
|
|
198
|
+
if (result > 0)
|
|
199
|
+
await this._updateCacheByWhere(table, where, null);
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
async bulkInsert(table, dataArray) {
|
|
203
|
+
const result = await this.db.bulkInsert(table, dataArray);
|
|
204
|
+
await this._clearCache(table);
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
async increment(table, increments, where = {}) {
|
|
208
|
+
const result = await this.db.increment(table, increments, where);
|
|
209
|
+
if (result > 0)
|
|
210
|
+
await this._updateCacheByWhere(table, where, null);
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
async decrement(table, decrements, where = {}) {
|
|
214
|
+
const result = await this.db.decrement(table, decrements, where);
|
|
215
|
+
if (result > 0)
|
|
216
|
+
await this._updateCacheByWhere(table, where, null);
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
async close() {
|
|
220
|
+
if (this.redisClient) {
|
|
221
|
+
await this.redisClient.quit();
|
|
222
|
+
this.redisClient = null;
|
|
223
|
+
}
|
|
224
|
+
await this.db.close();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
exports.CacheWrapper = CacheWrapper;
|
|
228
|
+
exports.default = CacheWrapper;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IDatabase } from './IDatabase';
|
|
2
|
+
import { DatabaseOptions } from './types';
|
|
3
|
+
import MigrationManager from './migration';
|
|
4
|
+
import ZPackAdapter, { ZPackDatabase } from './zpack';
|
|
5
|
+
/**
|
|
6
|
+
* Belirtilen adaptör tipine göre bir veritabanı örneği oluşturur ve döndürür.
|
|
7
|
+
* Bu bir "Fabrika Fonksiyonu"dur.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createDatabase(options: DatabaseOptions): IDatabase;
|
|
10
|
+
export { MigrationManager, ZPackDatabase, ZPackAdapter };
|
|
11
|
+
export default createDatabase;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ZPackAdapter = exports.ZPackDatabase = exports.MigrationManager = void 0;
|
|
40
|
+
exports.createDatabase = createDatabase;
|
|
41
|
+
const mysql_1 = __importDefault(require("./mysql"));
|
|
42
|
+
const sqlite_1 = __importDefault(require("./sqlite"));
|
|
43
|
+
const mongodb_1 = __importDefault(require("./mongodb"));
|
|
44
|
+
const json_1 = __importDefault(require("./json"));
|
|
45
|
+
const pg_1 = __importDefault(require("./pg"));
|
|
46
|
+
const redis_1 = __importDefault(require("./redis"));
|
|
47
|
+
const cacheWrapper_1 = __importDefault(require("./cacheWrapper"));
|
|
48
|
+
const migration_1 = __importDefault(require("./migration"));
|
|
49
|
+
exports.MigrationManager = migration_1.default;
|
|
50
|
+
const zpack_1 = __importStar(require("./zpack"));
|
|
51
|
+
exports.ZPackAdapter = zpack_1.default;
|
|
52
|
+
Object.defineProperty(exports, "ZPackDatabase", { enumerable: true, get: function () { return zpack_1.ZPackDatabase; } });
|
|
53
|
+
const adapters = {
|
|
54
|
+
mysql: mysql_1.default,
|
|
55
|
+
sqlite: sqlite_1.default,
|
|
56
|
+
mongodb: mongodb_1.default,
|
|
57
|
+
postgres: pg_1.default,
|
|
58
|
+
json: json_1.default,
|
|
59
|
+
redis: redis_1.default,
|
|
60
|
+
zpack: zpack_1.default,
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Belirtilen adaptör tipine göre bir veritabanı örneği oluşturur ve döndürür.
|
|
64
|
+
* Bu bir "Fabrika Fonksiyonu"dur.
|
|
65
|
+
*/
|
|
66
|
+
function createDatabase(options) {
|
|
67
|
+
const { adapter, config } = options;
|
|
68
|
+
if (!adapter || !adapters[adapter]) {
|
|
69
|
+
throw new Error(`Geçersiz veya desteklenmeyen adaptör: ${adapter}. Desteklenenler: ${Object.keys(adapters).join(', ')}`);
|
|
70
|
+
}
|
|
71
|
+
if (!config) {
|
|
72
|
+
throw new Error(`'${adapter}' adaptörü için yapılandırma (config) gereklidir.`);
|
|
73
|
+
}
|
|
74
|
+
const DatabaseClass = adapters[adapter];
|
|
75
|
+
const dbInstance = new DatabaseClass(config);
|
|
76
|
+
if (config.cache) {
|
|
77
|
+
const wrapper = new cacheWrapper_1.default(dbInstance, config.cache);
|
|
78
|
+
return new Proxy(wrapper, {
|
|
79
|
+
get: (target, prop) => {
|
|
80
|
+
if (typeof target[prop] !== 'undefined') {
|
|
81
|
+
return target[prop];
|
|
82
|
+
}
|
|
83
|
+
else if (typeof target.db[prop] === 'function') {
|
|
84
|
+
return target.db[prop].bind(target.db);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return target.db[prop];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return dbInstance;
|
|
93
|
+
}
|
|
94
|
+
exports.default = createDatabase;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IDatabase } from './IDatabase';
|
|
2
|
+
import { JsonConfig } from './types';
|
|
3
|
+
export declare class JsonDatabase extends IDatabase {
|
|
4
|
+
private filePath;
|
|
5
|
+
private db;
|
|
6
|
+
private isDirty;
|
|
7
|
+
private isWriting;
|
|
8
|
+
private writeQueue;
|
|
9
|
+
private saveDebounceTimeout;
|
|
10
|
+
private saveInterval;
|
|
11
|
+
private initPromise;
|
|
12
|
+
constructor(config: JsonConfig);
|
|
13
|
+
private _load;
|
|
14
|
+
private _queueRequest;
|
|
15
|
+
private _processQueue;
|
|
16
|
+
private _scheduleSave;
|
|
17
|
+
private _saveNow;
|
|
18
|
+
private flushSync;
|
|
19
|
+
private _matches;
|
|
20
|
+
ensureTable(table: string): Promise<void>;
|
|
21
|
+
insert(table: string, data: Record<string, any>): Promise<number>;
|
|
22
|
+
update(table: string, data: Record<string, any>, where: Record<string, any>): Promise<number>;
|
|
23
|
+
delete(table: string, where: Record<string, any>): Promise<number>;
|
|
24
|
+
select<T = any>(table: string, where?: Record<string, any> | null): Promise<T[]>;
|
|
25
|
+
set(table: string, data: Record<string, any>, where: Record<string, any>): Promise<any>;
|
|
26
|
+
selectOne<T = any>(table: string, where?: Record<string, any> | null): Promise<T | null>;
|
|
27
|
+
bulkInsert(table: string, dataArray: Record<string, any>[]): Promise<number>;
|
|
28
|
+
increment(table: string, increments: Record<string, number>, where?: Record<string, any>): Promise<number>;
|
|
29
|
+
decrement(table: string, decrements: Record<string, number>, where?: Record<string, any>): Promise<number>;
|
|
30
|
+
close(): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export default JsonDatabase;
|