Skip to content
This page View Markdown Open in ChatGPT Open in Claude

Query for get data by stream

The body of query for get data, with the answer of get all by stream : the rows go out as the database sends them.

In short

  • POST /api/schema/<user-path>/<instance>/<database>/<table>/query-stream
  • The body of the query API : find is required.
  • The answer of get all by stream : read success at the end.
  • Never cached. Pre hooks run, post hooks do not.
Method POST
URL /api/schema/admin/mysql8/inventory/customers/query-stream
Body { find, select, sort, skip, limit, deep, getTotalCount }
Query params none
Answer data : a list of rows, sent as they come
Databases MongoDB, MySQL, MariaDB, PostgreSQL, SQL Server, Oracle, TiDB, Percona
Cached no : a stream always reads the database
From code g.sys.db.queryByStream
API id SCHEMA_POST_QUERY_STREAM
Without a schema /api/gen/admin/mysql8/inventory/customers/query-stream : below

The call

POST /api/schema/admin/mysql8/inventory/customers/query-stream
Body
{ "find": { "isActive": 1 }, "sort": "customer_id", "select": "first_name" }
Answer, written in bunches
{ "data": [ { "customer_id": 1, "first_name": "Bob" }, { "customer_id": 2, "first_name": "Alice" } ], "success": true, "statusCode": 200 }
  • The keys and operators of the query API work here, find and join and deep too.
  • An error after the first rows still closes the answer as JSON, with "success": false and the errors.
  • Everything else (hooks, columns, compression) is as on get all by stream.

From your code

1
2
3
4
5
const rows: any[] = [];
await g.sys.db.queryByStream({
    instance: 'mysql8', database: 'inventory', collection: 'customers',
    find: { isActive: 1 }, select: 'customer_id,first_name',
}, (row) => rows.push(row));
1
2
3
4
5
6
7
8
rows = []
await g.sys.db.query_by_stream(
    Query(
        'mysql8', 'inventory', 'customers',
        find={'isActive': 1}, select='customer_id,first_name',
    ),
    rows.append,
)
$rows = [];
$g->sys->db->queryByStream(
    new Query(
        'mysql8', 'inventory', 'customers',
        find: ['isActive' => 1], select: 'customer_id,first_name',
    ),
    function ($row) use (&$rows) {
        $rows[] = $row;
    },
);
1
2
3
4
5
var rows = new List<JsonObject>();
await g.Sys.Db.QueryByStream(new Query("mysql8", "inventory", "customers")
{
    Find = new JsonObject { ["isActive"] = 1 }, Select = "customer_id,first_name",
}, row => rows.Add(row));
rows := []am.M{}
if err := g.Sys.Db.QueryByStream(am.Query{
    Instance: "mysql8", Database: "inventory", Collection: "customers",
    Find: am.M{"isActive": 1}, Select: "customer_id,first_name",
}, func(row am.M) error {
    rows = append(rows, row)
    return nil
}); err != nil {
    return nil, err
}
1
2
3
4
5
6
7
8
9
let mut rows = Vec::new();
g.sys.db.query_by_stream(
    Query::new("mysql8", "inventory", "customers")
        .find(json!({ "isActive": 1 })).select("customer_id,first_name"),
    |row| {
        rows.push(row.clone());
        Ok(())
    },
)?;
1
2
3
var rows = new ArrayList<JsonObject>();
g.sys.db.queryByStream(new Query("mysql8", "inventory", "customers")
    .find(Map.of("isActive", 1)).select("customer_id,first_name"), row -> rows.add(row));
1
2
3
4
5
val rows = mutableListOf<JsonObject>()
g.sys.db.queryByStream(
    Query("mysql8", "inventory", "customers")
        .find(mapOf("isActive" to 1)).select("customer_id,first_name"),
) { row -> rows.add(row) }

Without a schema : /api/gen

Every table also answers this operation under /api/gen, with or without a schema :

URL /api/gen/admin/mysql8/inventory/customers/query-stream
API id GEN_POST_QUERY_STREAM
From code g.sys.db.gen.queryByStreamGen

find matches the type you send. On MongoDB, a text that looks like an ObjectId is turned into one.

Headers and errors

This operation takes the request headers of every API. It answers the envelope, with the status codes and the messages of every API.

Related : All APIs · Table schema · Pre hooks · Post hooks · API group permission