1

I'm working on school project, which requires to show some simple data from mysql database in browser. I've read, that SQLJocky doesn't work in browser so I decided to make it like server-client app and run db on server side (got inspiration here: https://dart-lang.github.io/server/codelab/). But it didn't work, failed in creating client api with message:

*in ShutdownIsolate: Unhandled exception:
IsolateSpawnException: Unable to spawn isolate: Unhandled exception:
Load Error for "package:sqljocky/sqljocky.dart": No mapping for 'sqljocky' package when resolving 'package:sqljocky/sqljocky.dart'.
#0      _asyncLoadErrorCallback (dart:_builtin:155)
#1      _asyncLoadError (dart:_builtin:566)
#2      _loadPackage (dart:_builtin:605)
#3      _loadData (dart:_builtin:637)
#4      _loadDataAsync (dart:_builtin:657)
#5      _loadScriptCallback (dart:_builtin:153)
#6      _handleLoaderReply (dart:_builtin:370)
#7      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)
'file:///home/alenka/dart-pokusy/server-side-app/one-hour-codelab/server/7-serve/lib/server/dbConnector.dart': error: line 1 pos 1: library handler failed
import 'package:sqljocky/sqljocky.dart';
^
#0      Isolate.spawnUri.<spawnUri_async_body> (dart:isolate-patch/isolate_patch.dart)
#1      _asyncErrorWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:34)
#2      _RootZone.runBinary (dart:async/zone.dart:1154)
#3      _Future._propagateToListeners.handleError (dart:async/future_impl.dart:579)
#4      _Future._propagateToListeners (dart:async/future_impl.dart:641)
#5      _Future._completeError (dart:async/future_impl.dart:432)
#6      _SyncCompleter._completeError (dart:async/future_impl.dart:56)
#7      _Completer.completeError (dart:async/future_impl.dart:27)
#8      Isolate._spawnCommon.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:439)
#9      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)*

Does anyone have idea how to solve this problem, or how to get data from db in browser differently?

Code added containing things from SQLJocky:

`import 'package:sqljocky/sqljocky.dart';
 import 'dart:async';
...
  @ApiMethod(path: 'connect')
  Future<List<String>> dbConnect() async {
    List<String> rows = [];
    print('called dbConnect');
    var pool = new ConnectionPool(
        host: 'localhost',
        port: 3306,
        user: "root",
        password: null,
        db: 'project',
        max: 5);
    print('connection created');
    var results = await pool.query('select * from User');
    print('gonna write something from db');
    results.forEach( (row){
      print('Name: ${row[0]}, password: ${row[1]}');
      rows.add('Name: ${row[0]}, password: ${row[1]}');
    });
    return rows;
  }
`
alolapo
  • 21
  • 4
  • Can you please provide more code that shows how you are using `sqljocky`? The browser can't access the database directly except when the database provides some REST API but this is usually a security issue when a database allows direct access from the web. – Günter Zöchbauer May 09 '16 at 07:52
  • To the code from mentioned page, I've added this function to file /lib/server/piratesapi.dart this function: @ApiMethod(path: 'connect') Future> dbConnect() async { List rows = []; var pool = new ConnectionPool(host: 'localhost', port: 3306, user: "root", password: null, db: 'project', max: 5); var results = await pool.query('select * from User'); results.forEach( (row){ print('Name: ${row[0]}, password: ${row[1]}'); rows.add('Name: ${row[0]}, password: ${row[1]}'); }); return rows; } and got problem on Step 5 – alolapo May 09 '16 at 13:25
  • I also used commands pub get, dartanalyzer lib/server/piratesapi.dart and dart bin/piratesnest.dart without any problems and after last command, on browser was able to call http://localhost:8088/piratesApi/v1/connect which executed that function. It has printed right rows to console. – alolapo May 09 '16 at 13:55
  • Can you please edit the question and add the code there. Code in comments is an unreadable mess. – Günter Zöchbauer May 09 '16 at 14:31
  • The error message looks a bit like https://github.com/dart-lang/sdk/issues/25428. What dart version are you using? `dart --version` on the command line should print the version. – Günter Zöchbauer May 09 '16 at 17:00
  • Dart VM version: 1.14.2 (Tue Feb 9 15:05:59 2016) on "linux_ia32" – alolapo May 09 '16 at 17:13
  • 1
    Sounds like the version with the bug. The current stable is 1.15.x. Can you please update and try again? – Günter Zöchbauer May 09 '16 at 17:15
  • Things have moved on, I downloaded 1.16.0 (dartlang says it is a stable version). It doesn't write any errors, but now it doesn't do anything, even doesn't stop. Looks like he is still working but I can't see any output. Waited for him for cca 3 minutes. – alolapo May 10 '16 at 07:10
  • I would move the code to `main()` until it is working to ensure the problem is not with the framework you are also using (`@ApiMethod(path: 'connect')`) – Günter Zöchbauer May 10 '16 at 07:15
  • Sorry, I don't understand what you mean :) In that file piratesapi.dart is not any main() function, it is class with few functions marked as @ApiMethod – alolapo May 10 '16 at 07:36
  • Test the code outside the application. Just create a new file in `bin` with a `main()` function, copy your code there and debug it there until it is working and then copy it back to reduce complexity during debugging. – Günter Zöchbauer May 10 '16 at 07:46
  • I tested, found few problems (connected with changing version of linux), now are solved and command is still not responding. Still talking about that one in step 5: "pub global run rpc:generate client -i lib/server/piratesapi.dart -o lib/client". – alolapo May 10 '16 at 08:21
  • Hmm, I don't see a step 5 or `pub global run rpc:generate ...` mentioned above. Doesn't seem related to the question. – Günter Zöchbauer May 10 '16 at 08:23
  • https://dart-lang.github.io/server/codelab/ talking about code on this site. It is there, isn't it? – alolapo May 10 '16 at 08:29
  • I can't help you with RPC. I haven't tried it yet myself. I just tried to help with the sqljocky problem. – Günter Zöchbauer May 10 '16 at 08:31
  • 1
    Thank you anyway :) At least it doesn't finish with that one error, update helped. – alolapo May 10 '16 at 08:34
  • You could try with a bug report in https://github.com/dart-lang/www.dartlang.org if you followed the tutorial and it doesn't work. – Günter Zöchbauer May 10 '16 at 08:37

1 Answers1

0

Isolate your server side code and client side code into separates projects with their own pubspec.yaml.

I've found that sqljocky doesn't play nice with some of the client side libraries when both are in the pubspec.yaml.