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

floor can support son model? #715

Closed
zeqinjie opened this issue Dec 8, 2022 · 10 comments
Closed

floor can support son model? #715

zeqinjie opened this issue Dec 8, 2022 · 10 comments
Assignees

Comments

@zeqinjie
Copy link

zeqinjie commented Dec 8, 2022

db can support son model?

@entity
class Task {
  @PrimaryKey(autoGenerate: true)
  final int? id;

  final String message;

  final Detail detail;
   ...
}

@entity
class Detail {
   final String message;
   ...
}
@dkaera
Copy link
Collaborator

dkaera commented Dec 8, 2022

yep, to solve it quickly you can use type converters or you need to set up table relationships.

@zeqinjie
Copy link
Author

yep, to solve it quickly you can use type converters or you need to set up table relationships.

thx, can i return type when i delete data,now generate was queryNoReturn , return type was Future<void>

 @Query(
      'DELETE FROM ListChatModel WHERE uid in (:uids) AND selfImUId = :selfImUId')
  Future<int> deleteModelByUIds(
    List<String> uids,
    String selfImUId,
  );

  // generate code was  queryNoReturn
  @override
  Future<void> deleteModelByUIds(
    List<String> uids,
    String selfImUId,
  ) async {
    const offset = 2;
    final _sqliteVariablesForUids =
        Iterable<String>.generate(uids.length, (i) => '?${i + offset}')
            .join(',');
    await _queryAdapter.queryNoReturn(
        'DELETE FROM ListChatModel WHERE uid in (' +
            _sqliteVariablesForUids +
            ') AND selfImUId = ?1',
        arguments: [selfImUId, ...uids]);
  }

@dkaera
Copy link
Collaborator

dkaera commented Dec 12, 2022

I believe you receive an error when running generation. Because for a single return Future it must be nullable.
so in your case, for one record it should be
Future<int?> deleteModelByUId
Note that the delete operation returns the row ID if successful and -1 if not, according to the SQLite doc.

P.S.: for the list result it will be:
Future<List<int>> deleteModelByUIds

@zeqinjie
Copy link
Author

I believe you receive an error when running generation. Because for a single return Future it must be nullable. so in your case, for one record it should be Future<int?> deleteModelByUId Note that the delete operation returns the row ID if successful and -1 if not, according to the SQLite doc.

P.S.: for the list result it will be: Future<List<int>> deleteModelByUIds

@dkaera thx, i can generate success, but _queryAdapter.queryNoReturn was return Future . see the screenshot

Future<void> queryNoReturn(
    final String sql, {
    final List<Object>? arguments,
  }) async {
    // TODO #94 differentiate between different query kinds (select, update, delete, insert)
    //  this enables to notify the observers
    //  also requires extracting the table name :(
    await _database.rawQuery(sql, arguments);
  }

image

@dkaera
Copy link
Collaborator

dkaera commented Dec 13, 2022

that's odd 🤔
@zeqinjie can you share your DAO for DetailsChatItemModel please
Is this method declared as shown below?

@Query('DELETE FROM DetailsChatItemModel WHERE selfImUId = :selfImUId')
Future<int?> deleteModelBySelfImUId(String selfImUId)

@dkaera dkaera self-assigned this Dec 13, 2022
@zeqinjie
Copy link
Author

@dkaera example code

// DAO
 @Query(
      'DELETE FROM ListChatModel WHERE uid in (:uids) AND selfImUId = :selfImUId')
  Future<int?> deleteModelByUIds(
    List<String> uids,
    String selfImUId,
  );

// generate code
@override
  Future<int?> deleteModelByUIds(
    List<String> uids,
    String selfImUId,
  ) async {
    const offset = 2;
    final _sqliteVariablesForUids =
        Iterable<String>.generate(uids.length, (i) => '?${i + offset}')
            .join(',');
    await _queryAdapter.queryNoReturn(
        'DELETE FROM ListChatModel WHERE uid in (' +
            _sqliteVariablesForUids +
            ') AND selfImUId = ?1',
        arguments: [selfImUId, ...uids]);
  }

@dkaera
Copy link
Collaborator

dkaera commented Dec 19, 2022

@zeqinjie
sorry to be ahead of the curve. The current version of Floor does not support primitive Dart types for queries. I hope this will be published very soon #691

@zeqinjie
Copy link
Author

@zeqinjie sorry to be ahead of the curve. The current version of Floor does not support primitive Dart types for queries. I hope this will be published very soon #691

Thanks for the answer

@dkaera
Copy link
Collaborator

dkaera commented Dec 22, 2022

@zeqinjie feature has been released, welcome to check :)

@zeqinjie
Copy link
Author

zeqinjie commented Dec 28, 2022

@zeqinjie feature has been released, welcome to check :)

@dkaera OK thx

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