cloudloyaldb
v2.0.3
Published
Centralized NoSQL Database - MongoDB benzeri API ile cloud server'a veri saklama, real-time sync
Maintainers
Readme
CloudLoyalDB ☁️🚀
Centralized NoSQL Database with Multi-File Organization - MongoDB benzeri API ile cloud server'a veri saklama, real-time sync ve çoklu dosya yönetimi.
🌟 Yeni Özellikler
- ☁️ Centralized Storage - Tüm projeleriniz aynı veriye erişebilir
- ⚡ Real-time Sync - WebSocket ile anlık veri senkronizasyonu
- 📁 Multi-File System - Her database için ayrı JSON dosyası
- 🗂️ Organized Data -
data/klasöründe düzenli dosya yapısı - 🔄 Auto Backup - 24 saatte bir otomatik backup
- 🧹 Auto Cleanup - 2 günden eski backup'lar otomatik silinir
- 📡 Multi-Project - Birden fazla proje aynı database'e erişebilir
📦 Kurulum
Client (NPM Package)
npm install cloudloyaldbServer Kurulumu
# Server dosyalarını indirin
git clone https://github.com/yourusername/cloudloyaldb.git
cd cloudloyaldb
# Dependencies yükleyin
npm install
# Server'ı başlatın
npm run server🚀 Temel Kullanım
Bağlantı Kurma
const CloudLoyalDB = require('cloudloyaldb');
const db = new CloudLoyalDB({
serverUrl: 'http://localhost:3000',
apiKey: 'your-api-key',
projectId: 'my-project',
database: 'main' // data/main.json
});
// Server'a bağlan
await db.connect();
// Koleksiyon seç
await db.use('test');📁 Multi-Database Sistemi
Database Dosyaları
Server'da data/ klasöründe her database için ayrı JSON dosyası:
data/
├── main.json # Ana database
├── botveri.json # Discord bot verileri
├── ecommerce.json # E-ticaret verileri
├── analytics.json # Analitik verileri
└── logs.json # Log verileriDatabase Kullanımı
// Ana database
const mainDB = new CloudLoyalDB({
serverUrl: 'http://localhost:3000',
database: 'main' // → data/main.json
});
// Bot verileri
const botDB = new CloudLoyalDB({
serverUrl: 'http://localhost:3000',
database: 'botveri' // → data/botveri.json
});
// E-ticaret verileri
const shopDB = new CloudLoyalDB({
serverUrl: 'http://localhost:3000',
database: 'ecommerce' // → data/ecommerce.json
});
await mainDB.connect();
await botDB.connect();
await shopDB.connect();🎯 Pratik Örnekler
Discord Bot Yönetimi - data/botveri.json
const botDB = new CloudLoyalDB({
database: 'botveri'
});
await botDB.connect();
await botDB.use('discord_bots');
// Bot ekle
await botDB.set('loyal_bot.name', 'LoyalBot');
await botDB.set('loyal_bot.token', 'BOT_TOKEN');
await botDB.push('loyal_bot.guilds', '1298554568468336660');
await botDB.set('loyal_bot.status', 'online');
// Bot durumunu kontrol
const botStatus = await botDB.get('loyal_bot.status'); // "online"
const hasBot = await botDB.has('loyal_bot'); // true
// Bot konfigürasyonu
await botDB.push('loyal_bot.features', 'moderation');
await botDB.push('loyal_bot.features', 'music');
await botDB.push('loyal_bot.features', 'fun');
console.log('Bot Özellikleri:', await botDB.get('loyal_bot.features'));
// ["moderation", "music", "fun"]E-ticaret Sistemi - data/ecommerce.json
const shopDB = new CloudLoyalDB({
database: 'ecommerce'
});
await shopDB.connect();
// Ürün yönetimi
await shopDB.use('products');
await shopDB.push('electronics', {
id: 'laptop_001',
name: 'MacBook Pro M2',
price: 45000,
stock: 15,
tags: ['apple', 'laptop', 'premium']
});
// Kullanıcı sipariş
await shopDB.use('orders');
await shopDB.set('order_001.customer', 'Ahmet Yılmaz');
await shopDB.set('order_001.total', 45000);
await shopDB.push('order_001.items', {
productId: 'laptop_001',
quantity: 1,
price: 45000
});
// Stok güncellemesi
const products = await shopDB.use('products').get('electronics');
products[0].stock -= 1; // Satış sonrası stok azalt
await shopDB.setByPriority('electronics', products[0], 0);Analytics Veri Toplama - data/analytics.json
const analyticsDB = new CloudLoyalDB({
database: 'analytics'
});
await analyticsDB.connect();
await analyticsDB.use('page_views');
// Sayfa görüntülenme sayacı
await analyticsDB.set('homepage.today', 150);
await analyticsDB.set('homepage.total', 98750);
// Kullanıcı aktivitesi
await analyticsDB.use('user_actions');
await analyticsDB.push('today', {
userId: 'user123',
action: 'login',
timestamp: new Date().toISOString(),
page: 'dashboard'
});
// İstatistik hesaplama
const todayViews = await analyticsDB.use('page_views').get('homepage.today');
const totalActions = await analyticsDB.use('user_actions').get('today');
console.log(`Bugün ${todayViews} görüntülenme, ${totalActions.length} kullanıcı eylemi`);🔧 Croxydb Tarzı API
SET - Veri Ekleme/Güncelleme
await db.set("x.y.z", "abc"); // abc
// Nested objeler
await db.set("user.profile.name", "Ali");
await db.set("user.profile.age", 25);
await db.set("user.settings.theme", "dark");GET/FETCH - Veri Alma
await db.get("x"); // {y: {z: "abc"}}
await db.fetch("x"); // {y: {z: "abc"}} - get() ile aynı
await db.get("x.y"); // {z: "abc"}
await db.get("x.y.z"); // "abc"
await db.get("user.profile"); // {name: "Ali", age: 25}
await db.get("user.profile.name"); // "Ali"ALL - Tüm Koleksiyon
await db.all(); // {x: {y: {z: "abc"}}, user: {profile: {name: "Ali", age: 25}}}PUSH - Array'e Ekleme
await db.push("a", "hello"); // ["hello"]
await db.push("a", "world"); // ["hello", "world"]
// Object array
await db.push("b", {test: "croxydb"}); // [{test: "croxydb"}]
await db.push("b", {test2: "croxydb2"}); // [{test: "croxydb"}, {test2: "croxydb2"}]
// Karmaşık objeler
await db.push("products", {
id: 1,
name: "Laptop",
price: 25000,
tags: ["electronics", "computer"]
});UNPUSH - Array'den Değer Silme
await db.unpush("a", "hello"); // ["world"]
await db.unpush("products", {id: 1}); // Object'i silerDELBYPRIORITY - Index ile Silme
await db.delByPriority("b", 0); // İlk elemanı sil
await db.delByPriority("b", 1); // İkinci elemanı sil
// [{test: "croxydb"}, {test2: "croxydb2"}] → [{test2: "croxydb2"}]SETBYPRIORITY - Index ile Güncelleme
await db.setByPriority("b", {newtest: "hey this is edited"}, 0);
// [{test2: "croxydb2"}] → [{newtest: "hey this is edited"}]
await db.setByPriority("products", {
id: 999,
name: "Updated Product",
price: 999
}, 0); // İlk ürünü güncellerHAS - Veri Kontrol
await db.has("x"); // true
await db.has("x.y"); // true
await db.has("x.y.z"); // true
await db.has("nonexistent"); // false
await db.has("user.profile.name"); // true
await db.has("user.profile.phone"); // falseDELETE - Veri Silme
await db.delete("x.y.z"); // true - Sadece z'yi siler
await db.delete("x.y"); // true - y object'ini siler
await db.delete("x"); // true - Tüm x object'ini siler
await db.delete("products"); // Array'i siler
await db.delete("user.profile.age"); // Nested field silerDELETEALL - Koleksiyon Temizleme
await db.deleteAll(); // true - Tüm koleksiyonu temizler
// Sonrasında
await db.all(); // {} - Boş obje döner🌐 Multi-Project Veri Paylaşımı
Project A - E-ticaret Backend
const ecommerceDB = new CloudLoyalDB({
serverUrl: 'http://localhost:3000',
apiKey: 'your-api-key',
projectId: 'ecommerce-backend',
database: 'ecommerce' // data/ecommerce.json
});
await ecommerceDB.connect();
await ecommerceDB.use('customers');
await ecommerceDB.set('customer123.name', 'Zeynep Öztürk');
await ecommerceDB.push('customer123.orders', {
id: 'order_001',
amount: 1500,
date: new Date().toISOString()
});Project B - Admin Dashboard (Aynı Database)
const adminDB = new CloudLoyalDB({
serverUrl: 'http://localhost:3000',
apiKey: 'your-api-key',
projectId: 'admin-dashboard',
database: 'ecommerce' // Aynı database!
});
await adminDB.connect();
await adminDB.use('customers');
// Project A'nın verilerine erişim
const customer = await adminDB.get('customer123');
console.log(customer.name); // "Zeynep Öztürk"
console.log(customer.orders); // [{id: 'order_001', amount: 1500, ...}]
// Müşteri statusu güncelle
await adminDB.set('customer123.status', 'VIP');
await adminDB.set('customer123.loyaltyPoints', 2500);Project C - Discord Bot (Farklı Database)
const botDB = new CloudLoyalDB({
serverUrl: 'http://localhost:3000',
apiKey: 'your-api-key',
projectId: 'discord-bot',
database: 'botveri' // data/botveri.json
});
await botDB.connect();
await botDB.use('discord_bots');
// Bot durumu güncelle
await botDB.set('loyal_bot.status', 'online');
await botDB.push('loyal_bot.active_guilds', '1298554568468336660');
// Real-time dinle
botDB.on('dataChanged', (change) => {
if (change.database === 'botveri') {
console.log('Bot verileri değişti:', change);
// Bot'u restart et veya config'i yenile
updateBotConfiguration(change);
}
});📊 Data Organization Benefits
File Yapısı Avantajları
| Özellik | Multi-File System | Single File | |---------|-------------------|-------------| | Performance | ✅ Sadece gerekli dosya yüklenir | ❌ Tüm veri RAM'de | | Organization | ✅ Domain'e göre ayrım | ❌ Karışık yapı | | Backup | ✅ Seçici backup | ❌ Tüm veri backup | | Collaboration | ✅ Team üyesi farklı DB'ye erişim | ❌ Conflict riski | | Maintenance | ✅ Kolay debug/inceleme | ❌ Karmaşık |
Database Seçimi Örnekleri
// Proje türüne göre database seçimi
const projectType = 'discord-bot';
let database;
switch(projectType) {
case 'discord-bot':
database = 'botveri'; // → data/botveri.json
break;
case 'e-commerce':
database = 'ecommerce'; // → data/ecommerce.json
break;
case 'analytics':
database = 'analytics'; // → data/analytics.json
break;
default:
database = 'main'; // → data/main.json
}
const db = new CloudLoyalDB({ database });
await db.connect();💾 Backup Sistemi
Her database için ayrı backup:
flydb-backups/
├── main-backup-2025-01-15T10-00-00-000Z.json
├── botveri-backup-2025-01-15T10-00-00-000Z.json
├── ecommerce-backup-2025-01-15T10-00-00-000Z.json
└── analytics-backup-2025-01-15T10-00-00-000Z.jsonManuel Backup
// Belirli database'i backup et
const backupResult = await db.backup('my-backup');
console.log('Backup oluşturuldu:', backupResult.backupFile);
// Tüm database'leri backup et
const allBackups = await db.backupAll();Otomatik Backup
# Server başladığında her database için kontrol
CloudLoyalDB: main.json - Son 10 dakika içinde backup mevcut
CloudLoyalDB: botveri.json - Backup oluşturuluyor...
CloudLoyalDB: ecommerce.json - Backup oluşturuluyor...📁 Veri Yapısı Örnekleri
data/main.json - Ana Database
{
"users": {
"user123": {
"name": "Ali Veli",
"email": "[email protected]",
"preferences": {
"theme": "dark",
"language": "tr"
}
}
},
"system_config": {
"version": "1.0.0",
"maintenance": false
}
}data/botveri.json - Discord Bot Database
{
"discord_bots": {
"loyal_bot": {
"name": "LoyalBot",
"token": "***",
"guilds": ["1298554568468336660"],
"status": "online",
"features": ["moderation", "music", "fun"],
"commands": {
"ban": {"enabled": true, "permission": "ADMINISTRATOR"},
"kick": {"enabled": true, "permission": "KICK_MEMBERS"}
}
}
},
"guild_settings": {
"1298554568468336660": {
"prefix": "!",
"welcome_channel": "123456789",
"mod_role": "987654321"
}
}
}data/ecommerce.json - E-ticaret Database
{
"products": {
"electronics": [
{
"id": "laptop_001",
"name": "MacBook Pro M2",
"price": 45000,
"stock": 15,
"tags": ["apple", "laptop", "premium"]
}
]
},
"customers": {
"customer123": {
"name": "Zeynep Öztürk",
"email": "[email protected]",
"orders": [
{
"id": "order_001",
"total": 45000,
"status": "completed"
}
]
}
}
}⚡ Real-time Events
// Tüm database değişikliklerini dinle
db.on('dataChanged', (change) => {
const { database, collection, path, value, operation, timestamp } = change;
console.log(`[${database}] ${collection}/${path} ${operation}:`, value);
});
// Sadece bot verilerini dinle
botDB.on('dataChanged', (change) => {
if (change.database === 'botveri' && change.collection === 'discord_bots') {
console.log('Bot konfigürasyonu değişti:', change);
// Bot'u yeniden başlat
restartBot(change.path);
}
});
// Belirli koleksiyonu dinle
ecommerceDB.watch('orders', (change) => {
console.log('Yeni sipariş:', change);
// Email gönder, stok güncelle
processNewOrder(change);
});🎯 Hızlı Test
# 1. Server'ı başlat
npm run server
# 2. Demo'yu çalıştır (multi-database test)
npm run demo
# 3. Özel database testi
node -e "
const CloudLoyalDB = require('./index.js');
const db = new CloudLoyalDB({database: 'test'});
db.connect().then(() => {
db.use('example').set('key', 'value');
console.log('data/test.json created!');
});
"💡 Croxydb'den Migration
// Eski croxydb kodu
const db = require("croxydb");
db.set("x.y.z", "abc");
const data = db.get("x");
db.push("a", "hello");
// Yeni CloudLoyalDB kodu
const db = new CloudLoyalDB({
database: 'main' // Spesifik database seç
});
await db.connect();
await db.use('main');
await db.set("x.y.z", "abc");
const data = await db.get("x");
await db.push("a", "hello");🔧 API Reference
| Method | Syntax | Açıklama | Örnek |
|--------|--------|----------|-------|
| set() | await db.set(path, value) | Veri ekle/güncelle | await db.set("user.name", "Ali") |
| get() | await db.get(path) | Veri al | await db.get("user.name") |
| fetch() | await db.fetch(path) | get() ile aynı | await db.fetch("user") |
| all() | await db.all() | Tüm koleksiyon | await db.all() |
| push() | await db.push(path, value) | Array'e ekle | await db.push("hobbies", "reading") |
| unpush() | await db.unpush(path, value) | Array'den değer sil | await db.unpush("hobbies", "gaming") |
| delByPriority() | await db.delByPriority(path, index) | Index ile sil | await db.delByPriority("arr", 0) |
| setByPriority() | await db.setByPriority(path, value, index) | Index ile güncelle | await db.setByPriority("arr", "new", 1) |
| has() | await db.has(path) | Veri var mı | await db.has("user.name") |
| delete() | await db.delete(path) | Veri sil | await db.delete("user.age") |
| deleteAll() | await db.deleteAll() | Koleksiyonu temizle | await db.deleteAll() |
| use() | await db.use(collection) | Koleksiyon seç | await db.use("users") |
🌟 Avantajlar
| Özellik | CloudLoyalDB | Croxydb | MongoDB | |---------|--------------|---------|---------| | Multi-Database | ✅ Dosya bazlı organizasyon | ❌ Tek dosya | ✅ Database/Collection | | Real-time Sync | ⚡ WebSocket anlık | ❌ Yok | ❌ Change Streams kompleks | | Easy Setup | 🚀 Tek komut | 🚀 Tek komut | ❌ Karmaşık kurulum | | File Organization | 📁 data/ klasöründe düzenli | 📄 Tek dosya | 🗄️ Binary storage | | Backup System | 🔄 Otomatik per-database | ❌ Manuel | ✅ Professional | | Team Collaboration | 👥 Database bazlı paylaşım | ❌ Zor | ✅ User management |
📞 Deployment
Docker ile Multi-Database
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
# Data klasörü oluştur
RUN mkdir -p data
EXPOSE 3000 3001
CMD ["node", "server.js"]Volume mounting
# Data klasörünü host'a bağla
docker run -v $(pwd)/data:/app/data -p 3000:3000 -p 3001:3001 cloudloyaldbLisans
MIT
🚀 CloudLoyalDB Multi-File System ile verilerinizi organize edin!
📧 Sorularınız için: GitHub Issues
