Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@

📚 **Documentation**: Visit our [documentation site](https://quantadb.netlify.app/) for detailed guides and API references.

A high-performance pure Dart local database implementation using LSM-Tree architecture. QuantaDB is designed to provide a fast, reliable, and easy-to-use data storage solution for both Flutter applications and pure Dart projects.
A high-performance, type-safe NoSQL database for Dart and Flutter applications.

<p align="center">
<img src="https://raw.githubusercontent.com/champ96k/quanta_db/master/logo.png" alt="QuantaDB Logo" width="400"/>
</p>

## Features

- 🚀 **High Performance**: LSM-Tree based storage engine optimized for speed
- 🔒 **Data Security**: Built-in encryption support for sensitive data
- 📊 **Advanced Indexing**: Support for single, composite, and unique indexes
- 🔄 **Real-time Updates**: Reactive queries with change notifications
- 🎯 **Type Safety**: Strong typing with code generation
- 📱 **Cross-Platform**: Works on all platforms supported by Dart/Flutter
- 🔍 **Query Engine**: Powerful query capabilities with filtering and sorting
- 🔄 **Transaction Support**: ACID compliant transactions
- 🚀 **Performance**: Optimized for speed with LSM-Tree storage
- 🔒 **Type Safety**: Compile-time type checking and validation
- 🔄 **Reactive**: Real-time data synchronization
- 📊 **Query Engine**: Powerful querying capabilities
- 🔄 **Transactions**: ACID-compliant transactions
- 📈 **Scalability**: Efficient handling of large datasets
- 🛠 **Developer Experience**: Annotation-driven code generation
- 🔄 **Schema Migrations**: Automatic schema version management
Expand Down Expand Up @@ -73,15 +70,15 @@ void main() async {
User({required this.id, required this.name, required this.email});
}

// Create a DAO
final userDao = UserDao(db);

// Insert data
final user = User(id: '1', name: 'John', email: 'john@example.com');
await userDao.insert(user);
await db.put('user:1', user);

// Query data
final users = await userDao.getAll();
final queryEngine = QueryEngine(db.storage);
final users = await queryEngine.query<User>(
Query<User>().where((user) => user.name.startsWith('J'))
);
print('Users: $users');

// Close the database
Expand Down Expand Up @@ -196,9 +193,12 @@ final String name;
final DateTime lastLogin;

// Watch for changes
final stream = userDao.watchLastLogin(user);
await for (final lastLogin in stream) {
print('User logged in at: $lastLogin');
final queryEngine = QueryEngine(db.storage);
final stream = queryEngine.watch<User, User>(
Query<User>().where((user) => user.lastLogin != null)
);
await for (final user in stream) {
print('User logged in at: ${user.lastLogin}');
}
```

Expand Down
12 changes: 9 additions & 3 deletions documentation/docs/features/id-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ This will generate IDs like: `usr_1647123456789`
```dart
void main() async {
final db = await QuantaDB.open('my_database');
final userDao = UserDao(db);

// Create user with auto-generated ID
final user = User(
Expand All @@ -106,7 +105,7 @@ void main() async {
email: 'john@example.com'
);

await userDao.insert(user);
await db.put('user:1', user);
print('Created user with ID: ${user.id}');

// Create user with manual ID
Expand All @@ -116,8 +115,15 @@ void main() async {
email: 'jane@example.com'
);

await userDao.insert(user2);
await db.put('user:2', user2);
print('Created user with ID: ${user2.id}');

// Query users
final queryEngine = QueryEngine(db.storage);
final users = await queryEngine.query<User>(
Query<User>()
);
print('Total users: ${users.length}');
}
```

Expand Down
10 changes: 8 additions & 2 deletions documentation/docs/features/type-safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class User {
// Type-safe operations
void main() async {
final db = await QuantaDB.open('my_database');
final userDao = UserDao(db);
final queryEngine = QueryEngine(db.storage);

// Create user with auto-generated ID
final user = User(
Expand All @@ -101,8 +101,14 @@ void main() async {
age: 30
);

await userDao.insert(user);
await db.put('user:1', user);
print('Created user with ID: ${user.id}');

// Query users
final users = await queryEngine.query<User>(
Query<User>().where((user) => user.age > 25)
);
print('Found ${users.length} users over 25');
}
```

Expand Down
10 changes: 5 additions & 5 deletions documentation/docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ void main() async {
User({required this.id, required this.name, required this.email});
}

// Create a DAO
final userDao = UserDao(db);

// Insert data
final user = User(id: '1', name: 'John', email: 'john@example.com');
await userDao.insert(user);
await db.put('user:1', user);

// Query data
final users = await userDao.getAll();
final queryEngine = QueryEngine(db.storage);
final users = await queryEngine.query<User>(
Query<User>().where((user) => user.name.startsWith('J'))
);
print('Users: $users');

// Close the database
Expand Down
61 changes: 35 additions & 26 deletions documentation/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,9 @@ class User {
}
```

### Using the Generated DAO
### Using Models with QuantaDB

```dart
// Get the DAO
final userDao = UserDao(db);

// Create a user
final user = User(
id: '1',
Expand All @@ -92,68 +89,80 @@ final user = User(
);

// Insert the user
await userDao.insert(user);
await db.put('user:1', user);

// Find by ID
final found = await userDao.findById('1');

// Find by email (using index)
final byEmail = await userDao.findByEmail('john@example.com');
final found = await db.get<User>('user:1');

// Update user
user.name = 'John Updated';
await userDao.update(user);
final updatedUser = User(
id: '1',
name: 'John Updated',
email: 'john@example.com',
age: 31
);
await db.put('user:1', updatedUser);

// Delete user
await userDao.delete('1');
await db.delete('user:1');
```

## Transactions

```dart
await db.transaction(() async {
await db.storage.transaction((txn) async {
// Create user
final user = User(
id: '1',
name: 'John',
email: 'john@example.com',
age: 30
);
await userDao.insert(user);
await txn.put('user:1', user);

// Create profile
final profile = Profile(
userId: user.id,
bio: 'Software Developer'
);
await profileDao.insert(profile);
await txn.put('profile:1', profile);
});
```

## Queries

```dart
// Create a query engine
final queryEngine = QueryEngine(db.storage);

// Find all users
final allUsers = await userDao.getAll();
final allUsers = await queryEngine.query<User>(
Query<User>()
);

// Find users by age
final youngUsers = await userDao.findByAge(30);
final youngUsers = await queryEngine.query<User>(
Query<User>().where((user) => user.age < 30)
);

// Complex query
final results = await userDao.query()
.where('age').greaterThan(18)
.and('name').startsWith('J')
.orderBy('age', descending: true)
.limit(10)
.execute();
final results = await queryEngine.query<User>(
Query<User>()
.where((user) => user.age > 18)
.where((user) => user.name.startsWith('J'))
.sortBy((user) => user.age)
.take(10)
);
```

## Real-time Updates

```dart
// Subscribe to changes
final subscription = userDao.watch().listen((event) {
print('User changed: ${event.data}');
final subscription = queryEngine.watch<User, User>(
Query<User>().where((user) => user.isActive)
).listen((user) {
print('User changed: ${user.name}');
});

// Later, unsubscribe
Expand All @@ -179,7 +188,7 @@ subscription.cancel();

4. **Code Organization**
- Keep models in separate files
- Use DAOs for data access
- Use proper key naming conventions
- Implement proper separation of concerns

## Tips
Expand Down
Loading