postgresql - 未捕获 未捕获错误 : Unsupported operation: Socket constructor in dart with postgresql

标签 postgresql dart database-connection

我正在尝试将 dart 与数据库连接(可选,如 postgrelsql、mongodb)。我安装了 postgresql 并创建了 db、table 并转到 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 [作为 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 无法在浏览器中运行。 Mongodb 确实有一个 HTTP API,允许直接从浏览器中运行的代码访问它。 通常,数据库访问由服务器上运行的服务处理,浏览器向该服务发送命令以存储和检索数据,然后该服务将请求转发到数据库。或者,您可以使用现成的服务器,例如 Firebase。

关于postgresql - 未捕获 未捕获错误 : Unsupported operation: Socket constructor in dart with postgresql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34605037/

相关文章:

flutter - 如何在构造函数体内调用super?

mysql - 如何正确连接我的 php (symfony) 容器和 mysql 容器?

flutter - 如何使用 Dart/flutter 将数字格式化为数千、数百万和数十亿?

flutter - 在 FutureBuilder 中访问多个 future 的结果

ruby-on-rails - Ruby on Rails - Neo4J 连接被拒绝

c# - 从应用程序的多个线程到数据库的多个连接是否会提高插入查询性能?

javascript - Postgres Sequelize 原始查询以获取计数返回字符串值

postgresql - B+树或B树

ruby-on-rails - 解决 PG::GroupingError: ERROR

postgresql - 如何导入或同步数据到Neo4?