Skip to content

Commit b691a50

Browse files
Copilotgraknol
andauthored
Complete documentation overhaul for new DbRecord API, advanced features, and UI redesign (#27)
* Initial plan * Add comprehensive documentation for new DbRecord API features Co-authored-by: graknol <1364029+graknol@users.noreply.github.com> * Complete documentation overhaul with getting started updates and MDX fixes Co-authored-by: graknol <1364029+graknol@users.noreply.github.com> * Remove migration paths from old to new API as requested Co-authored-by: graknol <1364029+graknol@users.noreply.github.com> * Replace default icons with emojis and implement fuscia theme Co-authored-by: graknol <1364029+graknol@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: graknol <1364029+graknol@users.noreply.github.com>
1 parent 28e4238 commit b691a50

File tree

15 files changed

+1707
-56
lines changed

15 files changed

+1707
-56
lines changed

docs/docs/core-library/advanced-features.md

Lines changed: 561 additions & 0 deletions
Large diffs are not rendered by default.

docs/docs/core-library/database-operations.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,39 @@ final database = DeclarativeDatabase(
1717

1818
## Basic CRUD Operations
1919

20+
### Working with Typed Records
21+
22+
```dart
23+
// Register your record types first (usually in main())
24+
RecordMapFactoryRegistry.register<User>(User.fromMap);
25+
26+
// Create a new user
27+
final newUser = User.create(database);
28+
newUser.name = 'John Doe';
29+
newUser.email = 'john@example.com';
30+
newUser.age = 30;
31+
await newUser.save(); // Automatically handles INSERT
32+
33+
// Query users with type safety
34+
final users = await database.queryTyped<User>((q) => q.from('users'));
35+
for (final user in users) {
36+
print('User: ${user.name} (${user.email})'); // Type-safe property access
37+
}
38+
39+
// Update a user
40+
final user = users.first;
41+
user.email = 'newemail@example.com';
42+
user.age = 31;
43+
await user.save(); // Automatically handles UPDATE (only modified fields)
44+
45+
// Delete a user
46+
await user.delete();
47+
```
48+
49+
### Direct Database Operations
50+
51+
For cases where you need direct control over the database operations:
52+
2053
### Insert Data
2154

2255
```dart
@@ -50,6 +83,43 @@ await database.insertAll('users', [
5083

5184
### Query Data
5285

86+
Using typed records:
87+
88+
```dart
89+
// Query all users with type safety
90+
final allUsers = await database.queryTyped<User>((q) => q.from('users'));
91+
92+
// Query with WHERE conditions
93+
final adultUsers = await database.queryTyped<User>((q) =>
94+
q.from('users').where('age >= ?', [18])
95+
);
96+
97+
// Query with ordering and limits
98+
final recentUsers = await database.queryTyped<User>((q) =>
99+
q.from('users')
100+
.orderBy('created_at DESC')
101+
.limit(10)
102+
);
103+
104+
// Complex queries with joins
105+
final usersWithPosts = await database.queryTyped<User>((q) =>
106+
q.from('users u')
107+
.join('posts p', 'p.user_id = u.id')
108+
.where('p.created_at > ?', [DateTime.now().subtract(Duration(days: 7))])
109+
.groupBy('u.id')
110+
.forUpdate('users') // Enable CRUD operations
111+
);
112+
113+
// Table-specific queries (automatically CRUD-enabled)
114+
final activeUsers = await database.queryTableTyped<User>('users',
115+
where: 'active = ?',
116+
whereArgs: [true],
117+
orderBy: 'name ASC',
118+
);
119+
```
120+
121+
Using direct database queries:
122+
53123
```dart
54124
// Query all records
55125
final allUsers = await database.query('users');
@@ -563,4 +633,7 @@ await db.insert('users', userData);
563633

564634
Now that you understand database operations, explore:
565635

636+
- [Typed Records](typed-records) - Work with typed record classes for enhanced type safety
637+
- [Exception Handling](exception-handling) - Handle database errors gracefully
638+
- [Advanced Features](advanced-features) - Garbage collection and other utilities
566639
- [Streaming Queries](streaming-queries) - Real-time data updates

0 commit comments

Comments
 (0)