【问题标题】:Uncaught Uncaught Error: Unsupported operation: Socket constructor in dart with postgresql未捕获未捕获错误:不支持的操作:带有 postgresql 的 dart 中的套接字构造函数
【发布时间】:2016-01-05 05:51:36
【问题描述】:

我正在尝试将 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) 在 null.Socket_connect (http://localhost:8080/dbconnection.dart.js:11612:13) 在 dart.Socket_connect [as call$2] (http://localhost:8080/dbconnection.dart.js:11614:14) 在 ConnectionImpl_connect_closure.dart.ConnectionImpl_connect_closure.call$0 (http://localhost:8080/dbconnection.dart.js:13515:28) 在 dart.Future_Future$sync (http://localhost:8080/dbconnection.dart.js:4723:28) 在 dart.ConnectionImpl.static.ConnectionImpl_connect (http://localhost:8080/dbconnection.dart.js:13468:18) 在 dart.connect (http://localhost:8080/dbconnection.dart.js:12861:14) 在 dart.PostgrelSqlconn (http://localhost:8080/dbconnection.dart.js:12836:7) 在主要 (http://localhost:8080/dbconnection.dart.js:12825:15) 在 _wrapJsFunctionForAsync_closure.dart._wrapJsFunctionForAsync [as _captured_protected_1] (http://localhost:8080/dbconnection.dart.js:2923:11) (http://localhost:8080/dbconnection.dart.js:2531)

【问题讨论】:

    标签: postgresql dart database-connection


    【解决方案1】:

    您似乎正试图在浏览器中运行此代码。 Postgresql 在浏览器中不起作用。 Mongodb 确实有一个 HTTP API,它允许直接从浏览器中运行的代码访问它。 通常数据库访问由服务器上运行的服务处理,浏览器向该服务发送命令以存储和检索数据,然后该服务将请求转发到数据库。或者,您可以使用 Firebase 等即用型服务器。

    【讨论】:

    • 在哪里可以编写服务器代码?将数据库连接到飞镖是否有任何其他明确的文档。
    • 在带有 main() {} 的 Dart 包的 bin 子目录中创建一个 main.dart 文件(只是一个示例名称)。我不了解 Dart 数据库访问的一般文档。使用过的数据库包(如 sqljocky)中的示例可能最接近文档和使用过的数据库的文档。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    • 2019-02-03
    • 2020-09-17
    • 2019-02-13
    • 2018-04-09
    相关资源
    最近更新 更多