View with Dao
#1687
-
Hi, I try to implement this SQL statement with a View: select c.firstname, c.lastname, p.role, p.checkin, p.checkout
from contracts c
inner join positions p on p.positionid = c.positionid and p.positiondb = c.positiondb; I created this View: abstract class BookingItems extends View {
Contracts get contracts;
Positions get positions;
@override
Query as() => select([
contracts.firstName,
contracts.lastName,
positions.role,
positions.checkIn,
positions.checkOut,
]).from(contracts).join([
innerJoin(
positions,
const CustomExpression<bool?>(
r'positions.positionid = contracts.positionid and positions.positiondb = contracts.positiondb',
),
),
]);
} This View works, I tested it with the Database view in IntelliJ. But when I now create a Dao for it, I get an error :-( @DriftAccessor(views: [BookingItems])
class BookingItemsDao extends DatabaseAccessor<AppDatabase> with _$BookingItemsDaoMixin {
BookingItemsDao(AppDatabase db) : super(db);
// Future<List<BookingItem>> selectAll() => select(bookingItems).get();
}
How can I use the View? Is a Dao the right way? |
Beta Was this translation helpful? Give feedback.
Answered by
ghost
Feb 16, 2022
Replies: 1 comment
-
Okay, I got it. Also, you need to tell the dao what tables you are using for views. @DriftAccessor(tables: [Contracts, Positions], views: [BookingItems])
class BookingItemsDao extends DatabaseAccessor<AppDatabase> with _$BookingItemsDaoMixin {
BookingItemsDao(AppDatabase db) : super(db);
// Future<List<BookingItem>> selectAll() => select(bookingItems).get();
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Okay, I got it. Also, you need to tell the dao what tables you are using for views.