GithubHelp home page GithubHelp logo

Comments (4)

simolus3 avatar simolus3 commented on June 3, 2024 1

Drift is not parsing custom queries. The problem are the double quotes around "Brazil". We compile sqlite3 with the recommended options, which means that things in double quotes are interpreted as references (so sqlite3 tries to search for a column named Brazil and then aborts the query because no such column exists). To use strings in SQL, use single quotes ('Brazil').

To enable legacy support for double-quoted string literals, add a setup parameter to NativeDatabase that calls rawDb.config.doubleQuotedStringLiterals = true.

from drift.

PrimeTimeTran avatar PrimeTimeTran commented on June 3, 2024

I poked around the repo trying to identify the issue but nothing sticks out to me here.

Might this be a parser issue? Super confusing why it complains no such column: Brazil when my query is:
SELECT * FROM customers WHERE "Country" = "Brazil";

One more thing, the SELECT works without a WHERE clause.
Screenshot 2024-04-14 at 11 45 49 PM

from drift.

PrimeTimeTran avatar PrimeTimeTran commented on June 3, 2024

@simolus3 thanks for your suggestion. That worked like a charm for Native. However I'm targeting web so this is how I got my setup working inside if web.dart.

DatabaseConnection connect() {
  return DatabaseConnection.delayed(Future(() async {
    final result = await WasmDatabase.open(
      databaseName: 'main',
      sqlite3Uri: Uri.parse('sqlite3.wasm'),
      driftWorkerUri: Uri.parse('drift_worker.js'),
      initializeDatabase: () async {
        final data = await rootBundle.load('assets/chinook.db');
        return data.buffer.asUint8List();
      },
    );

    if (result.missingFeatures.isNotEmpty) {
      debugPrint('Using ${result.chosenImplementation} due to unsupported '
          'browser features: ${result.missingFeatures}');
    }
    return result.resolvedExecutor;
  }));
}

Could you make a suggestion for this setup? Poking around inside of wasm.dart here I didn't see how I might do the same thing.

Forgive me if I missed it. Also thanks so much for your work!

from drift.

simolus3 avatar simolus3 commented on June 3, 2024

Doing this on the web is a little tricky because your app doesn't own the database, it just accesses it through a separate worker (drift_worker.js). We can't sent closures to workers, so no similar API exists.

You can write your own worker that calls WasmDatabase.workerMainForOpen() which takes a similar callback used to configure all databases opened by that worker. The file could look similar to this one, except that it would add the callback.
You can compile your own worker with dart compile js -O4 web/worker.dart, or automatically with build_runner by adding a dependency on build_web_compilers (that is also what the example app is doing so that I don't have to manually copy the compiled worker into it, see this build configuration for a starting point).

from drift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.