Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Vedsaga
    @vedsaga:matrix.org
    [m]
    There are many groups for many package like for bloc...
    Simon Binder
    @simolus3
    @vedsaga:matrix.org I'm not too familiar with Discord. If there's a public Flutter community server you know, maybe we can ask about setting up a channel for drift in there? I'm not sure if it makes sense to setup a server just for drift alone? Interesting idea though.
    1 reply
    seck saliou
    @saliouseck2009_twitter
    Hello,
    I'm looking for a way to make DataClass.fromJson use the sql column name for keys instead of the dart getter name.
    Mensch272
    @mensch272
    Hello,
    Do you know how to target a unique constraint such as UNIQUE(id, index) in DoUpdate.
    Simon Binder
    @simolus3
    @mensch272 You can use DoUpdate(..., target: [table.id, table.index])
    Vedsaga
    @vedsaga:matrix.org
    [m]
    Simolus3, I am really great full that you made this package :)
    Quite easy to learn and slowly I can get drive into SQL based on my needs... 🙂
    Mensch272
    @mensch272
    @simolus3 Thanks.
    Simon Binder
    @simolus3
    @vedsaga:matrix.org Awesome, glad to hear you like it :)
    Sachin Dahal
    @sachin-dahal
    Hello @simolus3 sir,
    I needed your help to update the data.
    I've used the stream flow but whenever I needed to update the state or fire up the stream, I needed to update the database by adding or updating the data on the table. Are there any other ways to fire the stream so that I get the updated data without modifying the data on the specific table?
    Simon Binder
    @simolus3
    @sachin-dahal How would the data change without being modified? I don't understand why there's a reason for the stream to update?
    Sachin Dahal
    @sachin-dahal
    I've used some value that gets sum up from the another table and that particular table data gets updated but the previous one remains the same, but only the data will be updated at the UI once the previous data gets updated too. So for this reason, I want to know that, are there any ways to get the stream data back from the table without adding or updating values on it?
    Simon Binder
    @simolus3
    @sachin-dahal Can you show how you're writing that query? A stream should get updated if any involved table changes.
    Sachin Dahal
    @sachin-dahal
    I've figured out the solution for that sir, I've updated the current table with a constant value, and the stream is getting refreshed sir.
    johrpan
    @johrpan:johrpan.de
    [m]
    Hello everyone! I have a little problem: I would like to open a database file using drift that resides in a user defined directory. So, I will only get access to that directory using Android's storage access framework. Because of that I don't get a regular file system path, but only a document URI, that I can use with the ContentResolver API. So it is possible to get a Java File from it, a file descriptor and an input stream. Is there a way to somehow plumb that into drift?
    1 reply
    And also: I only need read only access to the database. Maybe that facilitates the case?
    johrpan
    @johrpan:johrpan.de
    [m]
    Vedsaga: Thanks for taking the time to answer! I let the user select a folder that contains a database in whatever location on external storage. The database file will have a predictable name in case that's what you mean.
    Vedsaga
    @vedsaga:matrix.org
    [m]
    ok, got it. So, now what you shall do is you have to delay to creation of DB instance... In most case DI happens at run time
    johrpan
    @johrpan:johrpan.de
    [m]
    Yes, I already do that. The problem is, that I don't get an actual file name from the Android storage access framework API. Just an internal URI.
    1 reply
    Vedsaga
    @vedsaga:matrix.org
    [m]
    Oh no wait you could use this
    johrpan
    @johrpan:johrpan.de
    [m]
    Ok, I think I found something. I think, I'll migrate to the file_picker plugin from my current self-backed solution. A quick glance at the source code seems to reveal that it also uses the storage access framework on newer Android versions which is a requirement in my case. But it will also do some magic to reveal the real file paths. I'll try it out!
    Vedsaga
    @vedsaga:matrix.org
    [m]
    👍
    Sachin Dahal
    @sachin-dahal
    Hello sir,
    I have huge data collections and it took me nearly 1:36 sec to insert all of those into the database...
    Once the single item is inserted, its returned ID is used for another insert() statement which will run in the then() method of the first insert completion. Overall, the ID of the first inserted item is required to run 3 different insertion statements in the then() method. Currently, I am using forEach loop to insert data.
    Here how can I use the transactions((){}) to run these statements atomically?
    Anybody's help is appreciated...
    5 replies
    Vedsaga
    @vedsaga:matrix.org
    [m]
    Or using loop?
    Simon Binder
    @simolus3
    @johrpan:johrpan.de I wonder if you could use ContentResolver.openFileDescriptor for the document's URI, then use ParcelFileDesciptor.detachFd() to get the native FD and finally open /dev/fd/$fdFromParcel as a sqlite3 database. I guess it would break since sqlite3 stores a journal or WAL next to the input path and I don't know if that can be overridden. Might be easier to let a plugin manage the path handling for you :D
    Sachin Dahal
    @sachin-dahal
    drift.png
    drift-issue.png
    line number 1217, 1242, 1267, 1291
    -------------------------ISSUE----------------------------------
    [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Bad state: This database or transaction runner has already been closed and may not be used anymore.
    If this is happening in a transaction, you might be using the transaction without awaiting every statement in it.
    Simon Binder
    @simolus3
    The error message is correct here, you're not awaiting all operations. If you're doing forEach(() async {}), the result of what happens in forEach is not awaited. Instead, I would probably use a regular for loop (like for (final categoryModelMap in List.from(...)) {}). Alternatively, you can use Future.forEach(yourList, () async { /*action*/ }).
    Sachin Dahal
    @sachin-dahal
    Thank you for the help sir, I will try and get back to you
    Simon Binder
    @simolus3
    Sure :+1: These errors can be hard to spot unfortunately. Maybe it's easiest to start from the stack trace and see how that call might not be awaited all the way back up to the transaction callback.
    1 reply
    Sachin Dahal
    @sachin-dahal
    I really appreciate your help, sir
    It worked...🎉
    Simon Binder
    @simolus3
    Nice, glad you were able to get it working!
    Andrew Moore
    @andrewpmoore

    I've got a watch that I've defined in a provider for flutter, the provider only exists for the scope of a page. I get the data and then process through it in the provider with a .forEach on the stream and then notify the listeners. I've noticed that if while on the page if I insert data it seems from that point going forward that the more and more watches trigger.

    So, for example, if I go into the page, I'll see the .forEach is processed once. Then if I insert 3 records and come out and back into the page I'll see the .forEach get processed several times which means the more I go in and out the page the more notificationListners/setStates will be getting called. Is this what you'd expect to happen?

    Simon Binder
    @simolus3

    @andrewpmoore The problem is that forEach does something for each element in a stream. Query watches from drift are (most likely) infinite streams though, so the forEach never completes and you get a new listener whenever the page is opened. You can use a different stream API to dispose the listener after the provider is destroyed. If your model is a ChangeNotifier, you could do something like this:

    class MyModel extends ChangeNotifier {
      StreamSubscription? _subscription;
    
      MyModel(AppDatabase db) {
        _subscription = db.someStreamQuery().listen((data) {
          // do something, then notifyListeners()
        });
      }
    
      @override
      void dispose() {
        _subscription?.cancel();
        super.dispose();
      }
    }

    If you previously called .forEach in the create method of the provider, you'll also need to change that to .listen and make sure that you .cancel() the stream subscription once the provider is disposed. Or just use a StreamProvider I guess.

    Andrew Moore
    @andrewpmoore
    Perfect, thanks for the prompt and detailed response, it's a great package
    Simon Binder
    @simolus3
    Thanks :)
    Sachin Dahal
    @sachin-dahal

    Hello sir, I have a class where multiple methods are there where I have used transaction (for eg. CRUD methods with multiple insertion and updates) but after calling them one after another, it's displaying an error after the first one i.e. Bad state: This database or transaction runner has already been closed and may not be used

    What are the ways to fix it? Or how to close the first transaction so that the next won't display error messages?
    Can you help me out with any possible ways to solve this, sir?

    Simon Binder
    @simolus3
    I assume it's once again due to not awaiting everything inside a transaction block? Can you post some small sample code that shows what you're trying to do? @sachin-dahal
    Sachin Dahal
    @sachin-dahal
    transaction at creating.png
    This is a function that runs after a create function is called where a transaction() is defined
    deleteSalesBIAC.png
    Vedsaga
    @vedsaga:matrix.org
    [m]
    you are missing await at line 1978
    remember to add await keywords everywhere when you do Crud inside transactions irrespective of how many Crud for each you should await
    Sachin Dahal
    @sachin-dahal
    thank you @vedsaga:matrix.org
    I'll add them all and get back to you...
    Sachin Dahal
    @sachin-dahal
    Thanks for the help @vedsaga:matrix.org
    Yes, that missing await keyword was the problem
    Vedsaga
    @vedsaga:matrix.org
    [m]
    🙂👍
    Simon Binder
    @simolus3
    @sachin-dahal I also suggest configuring the analyzer to help catch these issues:
    # include this in analysis_options.yaml
    linter:
      rules:
        - unawaited_futures
    1 reply