Skip to content

Get all

Structure

Structure
let getAll = await g.sys.db.gen.getAllGen({
    instance: "INSTANCE_NAME", database: 'DB_NAME', collection: "COLLECTION_NAME",
    queryParams: {
        deep: JSON.stringify([{
            s_key: "SOURCE_COLLECTION_COLUMN_NAME",
            t_key: "TARGET_COLLECTION_COLUMN_NAME",
            t_col: "TARGET_COLLECTION_NAME",
            select: "COLUMN_NAMES"
        }]),
        select: "COLUMN_NAMES",
        limit: 2,
        sort: "COLUMN_NAME"
    }
});

Simple Get all with one condition

Simple Get all from table
let getAll = await g.sys.db.gen.getAllGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    queryParams: {
        find: {
            first_name: 'James'
        }
    }
});

With header

Get all with header
1
2
3
4
5
6
7
8
let getAll = await g.sys.db.gen.getAllGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    headers: {
        "x-am-response-case": "capitalCase"
    }
});

With header and queryParams

Get all with header and queryParams
let getAll = await g.sys.db.gen.getAllGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    headers: {
        "x-am-meta": "true"
    },
    queryParams: {
        select: "first_name,last_name"
    }
});

With multiple queryParams

Get all with multiple queryParams
let getAll = await g.sys.db.gen.getAllGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    headers: {
        "x-am-response-case": "capitalCase"
    },
    queryParams: {
        select: "first_name,last_name",
        limit: 2
    }
});

With all params

Get all with all params
let getAll = await g.sys.db.gen.getAllGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    headers: {
        "x-am-response-case": "capitalCase"
    },
    queryParams: {
        select: "first_name,last_name",
        limit: 1,
        sort: "customer_id",
        deep: [{
            s_key: "customer_id",
            t_key: "owner_id",
            t_col: "products",
            select: "proName,proDescription,proPrice"
        }]
    }
});

Multi-tenant

  • instance: "crm::acme" works on the database of the tenant acme of the multi-tenant instance crm.
  • With instance: "crm", the call works on the database of the tenant of the request: a custom API called with the x-am-tenant-username header passes it on to the APIs it calls. A request without a tenant works on the structure database.
Get all customers of the tenant acme
1
2
3
4
5
6
let getAll = await g.sys.db.gen.getAllGen({
    instance: "crm::acme", database: "crm", collection: "customers",
    queryParams: {
        sort: "customer_id"
    }
});
Get all customers of the tenant globex, named with the header of the call
1
2
3
4
5
6
let getAll = await g.sys.db.gen.getAllGen({
    instance: "crm", database: "crm", collection: "customers",
    headers: {
        "x-am-tenant-username": "globex"
    }
});