-
Notifications
You must be signed in to change notification settings - Fork 0
FAQ
Flow.db is a modern, lightweight JSON document database designed for Node.js applications. It provides built-in features like schema validation, encryption, and automatic backups while maintaining a simple and intuitive API.
- Simplicity: Easy to set up and use with minimal configuration
- Type Safety: Built with TypeScript for better development experience
- Performance: In-memory caching for fast data access
- Security: Built-in encryption for sensitive data
- Reliability: Automatic backup system
- Zero Dependencies: Minimal external dependencies
Yes, Flow.db is designed for both development and production environments. However, consider these factors:
- Data size and scaling requirements
- Backup and recovery needs
- Security requirements
- Performance requirements
Flow.db uses AES encryption to secure your data. When encryption is enabled:
- Data is encrypted before writing to disk
- Data is automatically decrypted when read
- Encryption key is required for all operations
const db = new Database({
encryption: true,
encryptionKey: process.env.ENCRYPTION_KEY
});You can combine schema validation with custom validation functions:
function validateUser(user: any): boolean {
// Schema validation
const isValidSchema = db.validateSchema(user, userSchema);
if (!isValidSchema) return false;
// Custom validation
if (user.age < 18) return false;
if (!isValidEmail(user.email)) return false;
return true;
}Flow.db handles basic concurrency through file system locks. For advanced cases:
// Use transactions for atomic operations
await db.transaction(async () => {
const user = await db.get('user:1');
user.points += 10;
await db.set('user:1', user);
});Yes, Flow.db works with both JavaScript and TypeScript:
const { Database } = require('flow.db');
const db = new Database({
path: '.flow'
});- Use Caching:
const db = new Database({
cacheEnabled: true,
maxCacheSize: 1000
});- Batch Operations:
// Instead of multiple sets
users.forEach(user => db.set(`user:${user.id}`, user));
// Use a single operation
db.set('users', users);- Index Frequently Queried Fields:
db.createIndex('users', 'email');- Individual document: Up to 16MB
- Total database size: Limited by available disk space
- Cache size: Configurable through options
-
"Cannot initialize database"
- Check directory permissions
- Verify path exists
- Ensure sufficient disk space
-
"Invalid encryption key"
- Key length must be 32 characters
- Key must be properly formatted
- Key must be consistent across restarts
-
"Schema validation failed"
- Check data structure matches schema
- Verify required fields are present
- Ensure data types are correct
try {
await db.set('key', value);
} catch (error) {
if (error.code === 'EACCES') {
console.error('Permission denied');
} else if (error.code === 'ENOSPC') {
console.error('No space left');
} else {
console.error('Unknown error:', error);
}
}Backups are created based on your configuration:
const db = new Database({
autoBackup: true,
backupInterval: 3600, // Every hour
maxBackups: 5 // Keep last 5 backups
});const db = new Database();
await db.restore('backup-2024-03-01');By default, backups are stored in:
.flow/backups/
├── backup-2024-03-01/
├── backup-2024-03-02/
└── backup-2024-03-03/
- Backup your data
- Update Flow.db package
- Run migration script if provided
- Test functionality
- Update application code if needed
async function reEncrypt(newKey: string) {
const data = await db.export();
const newDb = new Database({
encryption: true,
encryptionKey: newKey
});
await newDb.import(data);
}- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
- Use GitHub Issues
- Provide reproduction steps
- Include error messages
- Share relevant code snippets
- Open a GitHub Discussion
- Describe your use case
- Provide example code
- Explain benefits