query method

  1. @override
Future<PostgreSQLResult> query(
  1. String fmtString, {
  2. Map<String, dynamic>? substitutionValues,
  3. bool? allowReuse = true,
  4. int? timeoutInSeconds,
})
inherited

Executes a query on this context.

This method sends the query described by fmtString to the database and returns a Future whose value is the returned rows from the query after the query completes. The format string may contain parameters that are provided in substitutionValues. Parameters are prefixed with the '@' character. Keys to replace the parameters do not include the '@' character. For example:

    connection.query("SELECT * FROM table WHERE id = @idParam", {"idParam" : 2});

The type of the value is inferred by default, but should be made more specific by adding ':type" to the parameter pattern in the format string. For example:

    connection.query("SELECT * FROM table WHERE id = @idParam:int4", {"idParam" : 2});

Available types are listed in PostgreSQLFormatIdentifier.typeStringToCodeMap. Some types have multiple options. It is preferable to use the PostgreSQLFormat.id function to add parameters to a query string. This method inserts a parameter name and the appropriate ':type' string for a PostgreSQLDataType.

If successful, the returned Future completes with a List of rows. Each is row is represented by a List of column values for that row that were returned by the query.

By default, instances of this class will reuse queries. This allows significantly more efficient transport to and from the database. You do not have to do anything to opt in to this behavior, this connection will track the necessary information required to reuse queries without intervention. (The fmtString is the unique identifier to look up reuse information.) You can disable reuse by passing false for allowReuse.

Implementation

@override
Future<PostgreSQLResult> query(
  String fmtString, {
  Map<String, dynamic>? substitutionValues,
  bool? allowReuse = true,
  int? timeoutInSeconds,
}) =>
    _query(
      fmtString,
      substitutionValues: substitutionValues,
      allowReuse: allowReuse!,
      timeoutInSeconds: timeoutInSeconds,
    );