未捕获未捕获错误:不支持的操作:带postgresql的dart中的套接字构造函数
我正在尝试将dart与数据库连接(可选,如postgrelsql、mongodb)。我安装了postgresql并创建了db、table和goto pubspec.yaml,然后添加依赖项postgresql并运行pub get。 然后我提到了图书馆的档案未捕获未捕获错误:不支持的操作:带postgresql的dart中的套接字构造函数,postgresql,dart,database-connection,Postgresql,Dart,Database Connection,我正在尝试将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'; con
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()处
在null.Socket\u connect()处
在dart.Socket_connect[作为呼叫$2]()
在ConnectionImpl\u connect\u closure.dart.ConnectionImpl\u connect\u closure.call$0()
在dart.Future\u Future$sync()
在dart.ConnectionImpl.static.ConnectionImpl\u connect()处
在dart.connect()处
在dart.PostgrelSqlconn()处
大体上()
在"wrapJsFunctionForAsync"closure.dart."wrapJsFunctionForAsync[as"captured"protected(受保护)()()(1))()。Postgresql无法从浏览器中运行。Mongodb有一个HTTP API,允许直接从浏览器中运行的代码访问它。
通常,数据库访问由服务器上运行的服务处理,浏览器向该服务发送命令以存储和检索数据,该服务将请求转发给数据库。或者,您可以使用现成的服务器,如Firebase 我在哪里可以写服务器代码?是否有其他明确的文档用于将数据库连接到dart。使用
main(){}
在dart包的bin
子目录中创建一个main.dart
文件(只是一个示例名称)。我不知道从Dart访问数据库的一般文档。来自所用数据库包(如sqljocky)的示例可能与所用数据库的文档和文档最接近。