我正在尝试将dart连接到数据库(可选的如postgrelsql、mongodb)。我安装了postgresql,并创建了db、table和goto pubspec.yaml,然后添加相关性postgresql并运行pub get。然后我提到了库文件
import 'package:postgresql/postgresql.dart';连接细节
var uri = 'postgres://postgres:root@localhost:5432/testdb';
connect(uri).then((conn) {
}); 但是我发现了一些我无法理解的错误。请帮帮我。
Stack Trace:
Uncaught Uncaught Error: Unsupported operation: Socket constructor堆栈跟踪:不支持的操作: dart.wrapException (http://localhost:8080/dbconnection.dart.js:2531:15) at null.Socket_connect (http://localhost:8080/dbconnection.dart.js:11612:13) at dart.Socket_connect as call$2 at dart.Socket_connect (http://localhost:8080/dbconnection.dart.js:13515:28) at dart.Future_Future$sync (http://localhost:8080/dbconnection.dart.js:4723:28) at http://localhost:8080/dbconnection.dart.js:13468:18 (http://localhost:8080/dbconnection.dart.js:13468:18) at dart.connect (http://localhost:8080/dbconnection.dart.js:12861:14) at dart.PostgrelSqlconn (http://localhost:8080/dbconnection.dart.js:12836:7)_wrapJsFunctionForAsync_closure.dart._wrapJsFunctionForAsync 1 (http://localhost:8080/dbconnection.dart.js:2531)的main (http://localhost:8080/dbconnection.dart.js:12825:15)
发布于 2016-01-05 06:01:59
看起来您正在尝试在浏览器中运行这段代码。Postgresql在浏览器中无法工作。Mongodb确实有一个HTTP,它允许直接从浏览器中运行的代码访问它。通常,数据库访问由运行在服务器上的服务处理,浏览器向该服务发送命令以存储和检索数据,并将请求转发给数据库。或者,您也可以使用即插即用的服务器,如Firebase。
https://stackoverflow.com/questions/34605037
复制相似问题