【发布时间】:2020-11-07 02:00:36
【问题描述】:
我有一个 postgres 数据库,其中包含一个名为“users”的表。该表有四个字段:
- id BIGSERIAL 主键
- display_name TEXT NOT NULL,
- 电子邮件文本不为空
- 电话号码文本
我想从 dart 代码中添加数据。 我的尝试看起来像这样:
import "dart:io";
import "package:postgres/postgres.dart";
void main() async{
var connection = PostgreSQLConnection(
"localhost", 5432, "test",
username: "something", password: "notTellingYou");
try {
await connection.open();
} catch (e) {
print(e);
}
Map<String, dynamic> data = {
"display_name": "foo",
"email": "foo@gmail.com"
};
await setData(connection, "users", data);
}
Future<void> setData(PostgreSQLConnection connection, String table, Map<String, dynamic> data) async {
await connection.query("""
INSERT INTO $table(${data.keys})
VALUES ${data.values};
""");
}
问题是我遇到了异常
(PostgreSQLSeverity.error 42601:“display_name”处或附近的语法错误)
【问题讨论】:
标签: postgresql dart crud