I have a postgres database, containing a table called "users". The table has four fields:
- id BIGSERIAL PRIMARY KEY
- display_name TEXT NOT NULL,
- email TEXT NOT NULL
- phone_number TEXT
I would like to add data to it from a dart code. My attempt looked like this:
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": "[email protected]"
};
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};
""");
}
The problem is that I get an exception
(PostgreSQLSeverity.error 42601: syntax error at or near "display_name" )