AI SummaryA data architecture agent that guides developers through implementing robust data persistence using Room ORM, SQLite, and secure storage patterns for Android and desktop applications. Ideal for developers building apps that require reliable local data management with encryption and schema migrations.
Install
Copy this and paste it into Claude Code, Cursor, or any AI assistant:
I want to set up the "04-data-management" agent in my project. Please run this command in my terminal: # Add AGENTS.md to your project root curl --retry 3 --retry-delay 2 --retry-all-errors -o AGENTS.md "https://raw.githubusercontent.com/pluginagentmarketplace/custom-plugin-android/main/agents/04-data-management.md" Then explain what the agent does and how to invoke it.
Description
Data Persistence & Storage - Room ORM, SQLite, DataStore, encryption, migrations (62 hours)
Data Management Agent: Persistence & Storage Architecture
Master data persistence strategies for Android. Learn Room ORM (recommended), SQLite direct access, SharedPreferences, DataStore, and secure encryption. Understand schema design, migrations, and reactive data flows. Prerequisite: Fundamentals & Platform agents Duration: 62 hours | Level: Intermediate Topics: 8 major areas | Code Examples: 40+ real-world patterns ---
1. ROOM ORM (RECOMMENDED)
Room is the modern persistence layer providing type-safe database access with compile-time query verification.
1.1 Entity Design
`kotlin // Basic entity @Entity(tableName = "users") data class User( @PrimaryKey val id: Int, val name: String, val email: String, val createdAt: Long = System.currentTimeMillis(), // Ignore fields not stored in database @Ignore val isSelected: Boolean = false ) // Entity with customized column names @Entity(tableName = "products") data class Product( @PrimaryKey(autoGenerate = true) val id: Int = 0, @ColumnInfo(name = "product_name") val name: String, @ColumnInfo(name = "product_price") val price: Double, @ColumnInfo(typeAffinity = ColumnInfo.REAL) val rating: Float ) // Composite primary key @Entity(tableName = "order_items", primaryKeys = ["orderId", "productId"]) data class OrderItem( val orderId: Int, val productId: Int, val quantity: Int ) // Entity with foreign key (relationship) @Entity( tableName = "posts", foreignKeys = [ ForeignKey( entity = User::class, parentColumns = ["id"], childColumns = ["userId"], onDelete = ForeignKey.CASCADE // Delete posts when user deleted ) ], indices = [Index("userId")] // Index for faster queries ) data class Post( @PrimaryKey val id: Int, val userId: Int, val title: String, val content: String ) `
1.2 DAO (Data Access Objects)
`kotlin @Dao interface UserDao { // Query single item @Query("SELECT * FROM users WHERE id = :userId") suspend fun getUser(userId: Int): User? // Query multiple items @Query("SELECT * FROM users ORDER BY name ASC") suspend fun getAllUsers(): List<User> // Reactive query with Flow (auto-updates on changes) @Query("SELECT * FROM users ORDER BY name ASC") fun observeAllUsers(): Flow<List<User>> // Filtered query with parameters @Query("SELECT * FROM users WHERE name LIKE :pattern") suspend fun searchByName(pattern: String): List<User> // Count rows @Query("SELECT COUNT(*) FROM users") suspend fun getUserCount(): Int // Insert single item @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertUser(user: User) // Insert multiple items @Insert(onConflict = OnConflictStrategy.IGNORE) suspend fun insertUsers(users: List<User>) // Update item @Update suspend fun updateUser(user: User) // Delete item @Delete suspend fun deleteUser(user: User) // Delete by condition @Query("DELETE FROM users WHERE id = :userId") suspend fun deleteUserById(userId: Int) // Upsert (Update or Insert) @Upsert suspend fun upsertUser(user: User) // Complex query with JOIN @Query(""" SELECT users.id, users.name, COUNT(posts.id) as postCount FROM users LEFT JOIN posts ON users.id = posts.userId GROUP BY users.id ORDER BY postCount DESC """) suspend fun getUsersWithPostCount(): List<UserWithPostCount> // Transaction (all or nothing) @Transaction @Query("SELECT * FROM users WHERE id = :userId") suspend fun getUserWithPosts(userId: Int): UserWithPosts } // Data class for JOIN results data class UserWithPostCount( val id: Int, val name: String, val postCount: Int ) // Relation for nested objects data class UserWithPosts( @Embedded val user: User, @Relation( parentColumn = "id", entityColumn = "userId" ) val posts: List<Post> ) `
Discussion
Health Signals
My Fox Den
Community Rating
Sign in to rate this booster