Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autogenerated code return null instead of List<Object> #710

Closed
Pive01 opened this issue Nov 25, 2022 · 4 comments
Closed

Autogenerated code return null instead of List<Object> #710

Pive01 opened this issue Nov 25, 2022 · 4 comments
Assignees

Comments

@Pive01
Copy link

Pive01 commented Nov 25, 2022

May be related to issue #576

This is my dao


@dao
abstract class CardDao {

  @Insert(onConflict: OnConflictStrategy.ignore)
  Future<void> bulkAdd(List<Card> cardsDeckRefCollection);

  @Query("Select c.id, c.card_title,c.house,c.card_type, c.front_image,c.card_text,c.amber,c.rarity,cdj.count,cdj.is_anomaly,cdj.is_enhanced,cdj.is_legacy,cdj.is_maverick from cards as c INNER JOIN cards_deck_join as cdj on c.id=cdj.cardId where c.id IN (Select cardId from cards_deck_join where deckId =:deckId)")
  Future<List<RetrivedCard>> getCardsFromDeckId(int deckId);
}

and running flutter packages pub run build_runner build

generated this code

 @override
  Future<List<RetrivedCard>> getCardsFromDeckId(int deckId) async {
    await _queryAdapter.queryNoReturn(
        'Select c.id, c.card_title,c.house,c.card_type, c.front_image,c.card_text,c.amber,c.rarity,cdj.count,cdj.is_anomaly,cdj.is_enhanced,cdj.is_legacy,cdj.is_maverick from cards as c INNER JOIN cards_deck_join as cdj on c.id=cdj.cardId where c.id IN (Select cardId from cards_deck_join where deckId =?1)',
        arguments: [deckId]);
  }

which returns null ...so I manually had to change it to

  @override
  Future<List<RetrivedCard>> getCardsFromDeckId(int deckId) async {
    return _queryAdapter.queryList(
        'select c.id, c.card_title,c.house,c.card_type, c.front_image,c.card_text,c.amber,c.rarity,cdj.count,cdj.is_anomaly,cdj.is_enhanced,cdj.is_legacy,cdj'
            '.is_maverick from cards as c INNER JOIN cards_deck_join as cdj on c.id=cdj.cardId where c.id IN (Select cardId from cards_deck_join where deckId =?1)',
        arguments: [deckId],
        mapper: (Map<String, Object?> row) => RetrivedCard(
              row['id'] as String,
              row['card_title'] as String,
              row['house'] as String,
              row['card_type'] as String,
              row['front_image'] as String,
              row['card_text'] as String,
              row['amber'] as int,
              row['rarity'] as String,
              (row['is_maverick'] as int) == 1,
              (row['is_anomaly'] as int) == 1,
              (row['is_enhanced'] as int) == 1,
              row['count'] as int,
              (row['is_legacy'] as int) == 1,
            ));
  }
@dkaera
Copy link
Collaborator

dkaera commented Nov 28, 2022

Hey @Pive01
did you add entity annotation for RetrivedCard?
probably the analyzer can not generate the mapper for it.

@Pive01
Copy link
Author

Pive01 commented Nov 28, 2022

@OverRide
Future<List> getCardsFromDeckId(int deckId) async {
return _queryAdapter.queryList(
'select c.id, c.card_title,c.house,c.card_type, c.front_image,c.card_text,c.amber,c.rarity,cdj.count,cdj.is_anomaly,cdj.is_enhanced,cdj.is_legacy,cdj'
'.is_maverick from cards as c INNER JOIN cards_deck_join as cdj on c.id=cdj.cardId where c.id IN (Select cardId from cards_deck_join where deckId =?1)',
arguments: [deckId],
mapper: (Map<String, Object?> row) => RetrivedCard(
row['id'] as String,
row['card_title'] as String,
row['house'] as String,
row['card_type'] as String,
row['front_image'] as String,
row['card_text'] as String,
row['amber'] as int,
row['rarity'] as String,
(row['is_maverick'] as int) == 1,
(row['is_anomaly'] as int) == 1,
(row['is_enhanced'] as int) == 1,
row['count'] as int,
(row['is_legacy'] as int) == 1,
));
}

Yes there is... this is the code for the class


@JsonSerializable()
@entity
class RetrievedCard extends Card {

  bool is_legacy;
  int count;

  RetrievedCard(super.id, super.card_title, super.house, super.card_type, super.front_image, super.card_text, super.amber, super.rarity, super.is_maverick,
      super.is_anomaly, super.is_enhanced, this.count, this.is_legacy);

  factory RetrievedCard.fromJson(Map<String, dynamic> json) => _$RetrievedCardFromJson(json);
  Map<String, dynamic> toJson() => _$RetrievedCardToJson(this);
}

@dkaera
Copy link
Collaborator

dkaera commented Nov 29, 2022

@Pive01 I think for your case you need to use DatabaseView, which allows fetching data in this way.

@dkaera dkaera self-assigned this Dec 16, 2022
@dkaera
Copy link
Collaborator

dkaera commented Feb 12, 2023

closed since no activity

@dkaera dkaera closed this as completed Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants