Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Simon Binder
    @simolus3
    @stasvo You can do addInspection: INSERT INTO inspections VALUES $inspectionObject, but for those very simple queries I'd probably just use the Dart API (await into(inspections).insert(inspectionObject)).
    Stas
    @stasvo
    @simolus3 I guess you mean code without keyword VALUES, right? as in documentation which I found "INSERT INTO todos $row";
    Simon Binder
    @simolus3
    Oh right, without VALUES.
    Andrea Antonello
    @moovida

    Dear developers, I have an issue on ios compilation I am not able to understand, maybe someone already saw this.
    I have an app that depends on a library that uses sqlite3, version 1.1.2. My app depends on sqlite3_flutter_libs 0.5.0.
    When I run a build, I end up with errors related to a wrong version of the sqlite libs being loaded:

        [!] CocoaPods could not find compatible versions for pod "sqlite3":
          In snapshot (Podfile.lock):
            sqlite3 (= 3.32.3, ~> 3.32.3)
    
          In Podfile:
            sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/ios`) was resolved to 0.0.1, which depends on
              sqlite3 (~> 3.35.4)

    I ran a flutter run deps, but the tree looks clean.
    Does anyone have an idea what I might be doing wrong?

    The suggestion given is to:

        You have either:
         * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
         * changed the constraints of dependency `sqlite3` inside your development pod `sqlite3_flutter_libs`.
           You should run `pod update sqlite3` to apply changes you've made.

    but none of this solves the issues.
    I do not understand where this version mismatch comes from... :-(

    Andrea Antonello
    @moovida

    Ok, I have to apologize. No idea why, but it got solved with a pods cleanup like:

    flutter clean
    rm -Rf ios/Pods
    rm -Rf ios/.symlinks
    rm -Rf ios/Flutter/Flutter.framework
    rm -Rf ios/Flutter/Flutter.podspec
    rm ios/Podfile

    and rebuild. Just for reference.

    Simon Binder
    @simolus3
    No worries, glad you got it solved!
    afonseca69
    @afonseca69
    Hi everybody
    how can I join string field with integer fild on where clause?
    ..where((t) => (t.nome + t.inscricao + t.clienteid).contains(pdescricao))
    t.clienteid is integer and the other two are string
    Abd al-Rahman al-Ktefane
    @Abdktefane
    hello everybody
    i need to watch chunk of data so i'm using limit with watch and order by created date so the query will be something like this
    final query = select(backups)
    ..where((it) => it.status.equals(status.index) & it.modifier.equals(modifier.index))
    ..orderBy(
    [(it) => OrderingTerm(expression: it.createdDate, mode: asc ? OrderingMode.asc : OrderingMode.desc)],
    )..limit(limit!);
    return query.watch();
    but when inserting new data my stream notified !! why this happen if the observed chunk not changed or modified especially that created date have default value DateTime.now()
    Please help as there is something wrong with what I'm doing or it's limitation with moor ?
      final query = select(backups)
          ..where((it) => it.status.equals(status.index) & it.modifier.equals(modifier.index))
          ..orderBy(
            [(it) => OrderingTerm(expression: it.createdDate, mode: asc ? OrderingMode.asc : OrderingMode.desc)],
          )..limit(limit!);
    
        if (limit != null && limit != 0) {
          query.limit(limit);
        }
    
        return query.watch();
    Abd al-Rahman al-Ktefane
    @Abdktefane
    insert query
    Future<void> addNewImages(List<BackupsCompanion> rawImages) => batch(
            (batch) => batch.insertAll(
              backups,
              rawImages,
              mode: InsertMode.insertOrIgnore,
            ),
          );
    Simon Binder
    @simolus3
    @Abdktefane Streams work on a per-table basis, so they may update more often than expected. You might be able to use .distinct() on the stream to avoid unnecessary updates.
    Abd al-Rahman al-Ktefane
    @Abdktefane

    thank you it's work now but i have some truble with list of uint8 and equality
    my table

    BlobColumn get thumbData => blob()();

    query

    return query.watch().distinct((oldImages, newImages) =>const ListEquality().equals(oldImages,newImages)

    it always return false when i remove int8 from equality it's work

    @override
      bool operator ==(Object other) =>
          identical(this, other) ||
          (other is Backup &&
              other.path == this.path &&
              other.mime == this.mime &&
              // other.thumbData == this.thumbData &&
              other.assetId == this.assetId &&
              other.title == this.title &&
              other.status == this.status &&
              other.modifier == this.modifier &&
              other.createdDate == this.createdDate);
    CalvinGonsalves
    @CalvinGonsalves

    Hello everybody,
    I'm trying to migrate a date Column of type Text to DateTime.
    dateColumn is the column Im trying to change from Text to DateTime

    migrator.alterTable(TableMigration(
        affectedTable,
        columnTransformer: {
          affectedTable.dateColumn:
             affectedTable.dateColumn.cast<DateTime>(),
        },
      ));

    Performing the cast like this converts the Text date from "2021-05-27T14:19:58-04:00" to 2021 which is an integer. I know that seconds since epoch is stored in the moor table .
    How would I write a custom cast expression for this logic ? :

      DateTime date = DateTime.parse('2021-05-27T14:19:58-04:00').toLocal();
    
      print('${date.millisecondsSinceEpoch/1000}');  //1622139598

    Thanks :)

    Simon Binder
    @simolus3
    @CalvinGonsalves You could use affectedTable.dateColumn: FunctionCallExpression<DateTime>('strftime', [Constant('%s', FunctionCallExpression('datetime', affectedTable.dateColumn))]). Effectively, this does strftime('%s', datetime('2021-05-27T14:19:58-04:00')) which returns the UNIX timestamp that moor is using internally.
    CalvinGonsalves
    @CalvinGonsalves
    @simolus3 Thank you. link to your github discussion answer. :)
    Stas
    @stasvo
    Is it possible to write multiple quires wrapped in transaction in moor file?
    Simon Binder
    @simolus3
    @stasvo Not currently, no. But this does sound like an interesting feature, feel free to open a new issue for this :)
    Stas
    @stasvo
    @simolus3 ok :)
    Madhuprakash
    @KiraKmp

    Selectable<QueryRow>? data = appDb.customSelect(queryString);
    List<QueryRow> list =await data.get();

    when i try to get the list of QuryRow from selectable it breaks the code not throwing any exception

    Britannio Jarrett
    @britannio
    @simolus3 Hey, what are your thoughts on https://jlongster.com/future-sql-web? I'm looking for ways to speed up sqlite on Web as writes are painfully slow and this looks promising.
    Simon Binder
    @simolus3
    @britannio I've seen that and I think it's awesome! So far I didn't have the time to try it out though. It seems as you could just bind to that with package:js and use it with moor though. One thing that's a bit concerning to me is that it requires web worker hacks to synchronously invoke IndexedDb, so you'd have to manually copy over more files to spawn the worker.
    Now, we could have an architecture similar to asyncfvs, where we start async writes to IndexDb and already consider them for reads. With that we wouldn't need a web worker, but you'd loose durability.
    Stas
    @stasvo
    In which files of source code possible to see how code generated from moor files ?
    Simon Binder
    @simolus3
    @stasvo Moor currently compiles all generated code into a single .g.dart file generated for the database. This file contains all the generated classes and methods for all included moor files.
    Stas
    @stasvo
    @simolus3 Yes I know, I did mean another thing, for me interesting to see part of moor source code which generate .g.dart from moor files. For understand how works process of generate code from moor files.
    Simon Binder
    @simolus3
    Oh cool :) Actually it's a lot of parts. The sqlparser package parses the moor files and does simple static analysis on them. Then, code in this directory further does some moor-specific analysis across multiple files. Finally, this code is responsible for generating the .g.dart files.
    Stas
    @stasvo
    @simolus3 Thanks.
    João Baroni
    @joaobaroni_gitlab
    Hi guys
    i'm tryn to do a update query in my app using moor
    I'm trying to update a specific row by adding its current value with 1, for example
    someone knows how to do this?
    in moor documentation i found something similar but it only works with insert statement (DoUpdate)
    thanks for your attention guys =)
    João Baroni
    @joaobaroni_gitlab
    love from brazil
    Simon Binder
    @simolus3
    @joaobaroni_gitlab You can use update with a custom companion for this: update(yourTable).write(YourTableCompanion.custom(counter: yourTable.counter + Constant(1))).
    This would increase the counter by one for every row. If you want a specific row, you can put a .where in between. Or you can use whereSamePrimaryKey to filter for a specific row (similar to replace).
    João Baroni
    @joaobaroni_gitlab
    Simon, Thank you for your support. Your suggestion worked perfectly
    I take this opportunity to say that the work you have been doing is very important to the community. Moor is amazing
    thanks
    Simon Binder
    @simolus3
    Thanks for the kind words! :heart:
    Stas
    @stasvo
    I found that in my case "on delete cascade" doesnt work. I guess its because I need to set PRAGMA foreign_keys = ON; Where possible to set it if I mostly use moor files ?
    Simon Binder
    @simolus3
    @stasvo You'd still have to write that manually. You could put customStatement('PRAGMA foreign_keys = ON') inside your onCreate callback (or in onUpgrade as well to support existing databases).
    Matthew Clark
    @mclark4386
    so say I had a table Category that was basically just an id, name, "level of difficulty" and then I had a table that was Puzzle which had multiple categories via an Uint8List of the ids. Is there a way to do a subquery instead of a join so it's something like:
    select * from puzzles where categories in (select id from categories where level = 1);
    afonseca69
    @afonseca69
    Hi, In my flutter app I create a database file named for each login user. Each user has his own database. So when I log out and login with another user, I close the database, but it did not open again after the new user login. So is there a way to do this? To open an exist database or create a new one, I use LazyDatabase that returns VmDatabase. LazyDatabase _openConnection() {
    return LazyDatabase(() async {
    final dbFolder = await getApplicationDocumentsDirectory();
    //final dbFolder = await getExternalStorageDirectory();
    print(dbFolder.path);
    final file = File(p.join(dbFolder.path, '$bdinscricao.sqlite'));
    print(file);
    vgbdaberto = true;
    return VmDatabase(file, logStatements: true);
    });
    }

    class DbGestor extends _$DbGestor implements IDbGestor {
    static DbGestor instance = DbGestor._internal();
    late ClienteDAO clienteDAO;
    late ParametroDAO parametroDAO;
    late PedidoDAO pedidoDAO;
    late PedidoItemDAO pedidoitemDAO;
    late PrecoDAO precoDAO;
    late ProdutoDAO produtoDAO;
    late TituloDAO tituloDAO;

    DbGestor._internal() : super(_openConnection()) {
    clienteDAO = ClienteDAO(this);
    parametroDAO = ParametroDAO(this);
    pedidoDAO = PedidoDAO(this);
    pedidoitemDAO = PedidoItemDAO(this);
    precoDAO = PrecoDAO(this);
    produtoDAO = ProdutoDAO(this);
    tituloDAO = TituloDAO(this);
    }

    Simon Binder
    @simolus3
    @afonseca69 After you close a database, you need to create a new instance to re-open it. Are you doing that?