@aiao/rxdb-adapter-supabase
v0.0.7
Published
Supabase database adapter for AIAO RxDB framework.
Readme
rxdb-adapter-supabase
Supabase database adapter for AIAO RxDB framework.
Features
- ✅ Full CRUD operations (Create, Read, Update, Delete)
- ✅ Complex query conditions (
=,!=,>,<,>=,<=,in,between,startsWith, etc.) - ✅ Relationship queries (ONE_TO_ONE, ONE_TO_MANY, MANY_TO_ONE, MANY_TO_MANY)
- ✅ EXISTS / NOT EXISTS operators for checking related records
- ✅ COUNT queries with EXISTS support
- ✅ Ordering and pagination
- ✅ Real-time subscriptions via Supabase Realtime
Query Operators
Comparison Operators
=,!=- Equal / Not equal>,>=,<,<=- Greater / Less thanin,notIn- Value in / not in arraybetween- Value between rangestartsWith,endsWith,contains- String pattern matching
Relationship Operators
exists- Check if related record existsnotExists- Check if related record does not exist
EXISTS Operator Examples
// Find users who have orders
// 注意:使用实体定义中的关系名 'orders',而不是表名 'Order'
const usersWithOrders = await userRepo.find({
where: {
combinator: 'and',
rules: [{ field: 'orders', operator: 'exists' }]
}
});
// Find users who don't have id cards
// 使用关系名 'idCard',而不是表名 'IdCard'
const usersWithoutIdCard = await userRepo.find({
where: {
combinator: 'and',
rules: [{ field: 'idCard', operator: 'notExists' }]
}
});
// Count users with orders
const count = await userRepo.count({
where: {
combinator: 'and',
rules: [{ field: 'orders', operator: 'exists' }]
}
});重要:field 参数必须使用实体定义中的关系名(如 'idCard', 'orders'),而不是 Supabase 表名(如 'IdCard', 'Order')。
Known Limitations
Bidirectional ONE_TO_ONE Relationships
When a ONE_TO_ONE relationship has foreign keys on both sides (e.g., User.idCardId → IdCard and IdCard.ownerId → User), Supabase cannot automatically determine which foreign key to use for EXISTS queries.
Workaround: Redesign schema to have foreign key on only one side, or use the reverse relationship query.
// ❌ May fail with bidirectional ONE_TO_ONE
await userRepo.find({
where: { rules: [{ field: 'idCard', operator: 'exists' }] }
});
// ✅ Use ONE_TO_MANY instead (works correctly)
await userRepo.find({
where: { rules: [{ field: 'orders', operator: 'exists' }] }
});Testing
nx test rxdb-adapter-supabaseTest coverage: 60/62 tests passing (96.8%)
- ✅ 5/6 EXISTS operator tests
- ⏭️ 1 skipped (bidirectional ONE_TO_ONE limitation)
