database-connector-service
Advanced tools
Comparing version 1.0.1 to 1.0.2
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.redisService = exports.createQuery = exports.invalidateCache = exports.queryWithPagination = exports.transaction = exports.execute = exports.query = void 0; | ||
exports.redisService = exports.createQueryBuilder = exports.invalidateCache = exports.queryWithPagination = exports.transaction = exports.execute = exports.query = void 0; | ||
var database_1 = require("./core/database"); | ||
@@ -10,5 +10,5 @@ Object.defineProperty(exports, "query", { enumerable: true, get: function () { return database_1.query; } }); | ||
Object.defineProperty(exports, "invalidateCache", { enumerable: true, get: function () { return database_1.invalidateCache; } }); | ||
var query_builder_1 = require("./utils/query.builder"); | ||
Object.defineProperty(exports, "createQuery", { enumerable: true, get: function () { return query_builder_1.createQuery; } }); | ||
var builder_1 = require("./builder"); | ||
Object.defineProperty(exports, "createQueryBuilder", { enumerable: true, get: function () { return builder_1.createQueryBuilder; } }); | ||
var redis_service_1 = require("./services/redis.service"); | ||
Object.defineProperty(exports, "redisService", { enumerable: true, get: function () { return redis_service_1.redisService; } }); |
{ | ||
"name": "database-connector-service", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "description": "A TypeScript-based service for managing MySQL, MSSQL, and Redis connections.", |
163
README.md
@@ -46,82 +46,5 @@ # Database Connector Services | ||
```typescript | ||
import { createQuery, query, execute, transaction } from 'database-connector-service'; | ||
// Sorgu Oluşturucu Kullanımı | ||
const users = await createQuery('users') | ||
.select(['id', 'name', 'email']) | ||
.where({ active: true }) | ||
.orderBy('name') | ||
.cache('active-users', 3600) | ||
.getAll(); | ||
// Önbellekli direkt sorgu | ||
const result = await query( | ||
'SELECT * FROM users WHERE status = ?', | ||
['active'], | ||
{ | ||
cache: { | ||
key: 'active-users', | ||
ttl: 3600 | ||
} | ||
} | ||
); | ||
// İşlem örneği | ||
await transaction(async (trx) => { | ||
await trx.query('INSERT INTO users (name) VALUES (?)', ['John']); | ||
await trx.query('UPDATE stats SET total = total + 1'); | ||
}); | ||
import { createQueryBuilder, query, execute, transaction } from 'database-connector-service'; | ||
``` | ||
## Örnekler | ||
### Sorgu Oluşturucu | ||
```typescript | ||
// 1. Temel Sorgu | ||
const users = await createQuery('users') | ||
.select(['id', 'name', 'email']) | ||
.where({ active: true }) | ||
.orderBy('name') | ||
.getAll(); | ||
// 2. Birleştirmeler (Joins) | ||
const orders = await createQuery('orders') | ||
.select([ | ||
'orders.id', | ||
'orders.total', | ||
'users.name as user_name' | ||
]) | ||
.leftJoin('users', 'users.id = orders.user_id') | ||
.where({ 'orders.status': 'completed' }) | ||
.getAll(); | ||
// 3. Karmaşık Koşullar | ||
const stats = await createQuery('orders') | ||
.select([ | ||
'user_id', | ||
'COUNT(*) as order_count', | ||
'SUM(total) as total_amount' | ||
]) | ||
.where({ status: 'completed' }) | ||
.andWhere('created_at > ?', ['2024-01-01']) | ||
.groupBy('user_id') | ||
.having('total_amount > ?', [1000]) | ||
.orderBy('total_amount', 'DESC') | ||
.getAll(); | ||
// 4. Tek Kayıt | ||
const user = await createQuery('users') | ||
.where({ id: 1 }) | ||
.getOne(); | ||
// 5. Sayfalama | ||
const pagedResults = await createQuery('users') | ||
.where({ active: true }) | ||
.orderBy('name') | ||
.limit(10) | ||
.offset(0) | ||
.getAll(); | ||
``` | ||
### Direkt Sorgular | ||
@@ -159,4 +82,77 @@ | ||
); | ||
// İşlem örneği | ||
await transaction(async (trx) => { | ||
await trx.query('INSERT INTO users (name) VALUES (?)', ['John']); | ||
await trx.query('UPDATE stats SET total = total + 1'); | ||
}); | ||
``` | ||
### Sorgu Oluşturucu | ||
``` typescript | ||
const users = createQueryBuilder('users'); | ||
// SELECT örneği | ||
const activeUsers = await users | ||
.select() | ||
.select('id', 'name', 'email') | ||
.where('status', '=', 'active') | ||
.leftJoin('orders', 'users.id = orders.user_id') | ||
.groupBy('role') | ||
.having('COUNT(*) > 5') | ||
.orderBy('created_at', 'DESC') | ||
.cache('active-users', 3600) | ||
.execute<User>(); | ||
// INSERT örneği | ||
await users | ||
.insert() | ||
.values({ | ||
name: 'John', | ||
email: 'john@example.com' | ||
}) | ||
.invalidateCache('users', 'stats') | ||
.execute(); | ||
// UPDATE örneği | ||
await users | ||
.update() | ||
.set({ | ||
status: 'inactive', | ||
updated_at: new Date() | ||
}) | ||
.where('id', '=', 1) | ||
.invalidateCache('users') | ||
.execute(); | ||
// DELETE örneği | ||
await users | ||
.delete() | ||
.where('status', '=', 'inactive') | ||
.invalidateCache('users', 'stats') | ||
.execute(); | ||
// Transaction örneği | ||
await users.transaction(async (trx) => { | ||
await users | ||
.insert() | ||
.values({ name: 'John' }) | ||
.execute(); | ||
await users | ||
.update() | ||
.set({ total: 100 }) | ||
.where('type', '=', 'user') | ||
.execute(); | ||
}); | ||
// Pagination örneği | ||
const { data, pagination } = await users | ||
.select() | ||
.where('active', '=', true) | ||
.orderBy('name') | ||
.paginate<User>({ page: 1, pageSize: 20 }); | ||
``` | ||
### Önbellek Yönetimi | ||
@@ -166,7 +162,10 @@ | ||
// 1. Sorgu Oluşturucu ile Önbellekleme | ||
const users = await createQuery('users') | ||
.where({ active: true }) | ||
.cache('active-users', 3600) // anahtar ve TTL (saniye) | ||
.getAll(); | ||
const users = createQueryBuilder('users'); | ||
const users = await createQueryBuilder('users') | ||
.select() | ||
.where('status', '=', 'active') | ||
.cache('active-users', 3600) | ||
.execute<User>(); | ||
// 2. Çoklu Önbellek Desenlerini İnvalidasyon | ||
@@ -173,0 +172,0 @@ await invalidateCache(['users', 'orders', 'stats']); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22
35497
801
248
1