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

Get indexes

Lists the indexes of a table in the same format for every database : the name, the fields with their direction, whether it is unique, and the access method when the database says it.

Method POST
URL /api/system-api/admin/get-indexes : admin is the user path of your account
Body { instance, database, collection | table } or an array of them
Answer data : an array of indexes, or an array of arrays
From code g.sys.system.getIndexes

The call

Body
{ "instance": "mysql8", "database": "inventory", "table": "orders" }
Answer
{
    "success": true,
    "statusCode": 200,
    "data": [
        { "name": "PRIMARY", "key": { "id": 1 }, "unique": true },
        { "name": "am_ix_orders_customer_id_status_3f9a1c", "key": { "customer_id": 1, "status": -1 }, "unique": false, "method": "BTREE" }
    ]
}
Property Meaning
name Index name.
key The fields in order, with their direction : 1 ascending, -1 descending, hashed or text on MongoDB.
unique A unique index (the primary key included).
method The access method when the database tells it (BTREE, HASH, gin…).
  • An array of tables answers an array of lists, in the same order.

From code

g.sys.system.getIndexes makes the same call from your code, whatever the settings of this API say about HTTP callers.

The indexes of a table

The indexes of a table, in the same format for every database.

1
2
3
4
5
6
7
8
9
const indexes = await g.sys.system.getIndexes({
    instance: 'mysql8',
    database: 'inventory',
    table: 'orders',
});
// [
//     { name: 'PRIMARY', key: { id: 1 }, unique: true },
//     { name: 'am_ix_orders_customer_id_status_3f9a1c', key: { customer_id: 1, status: -1 }, unique: false, method: 'BTREE' },
// ]
1
2
3
4
5
6
7
8
9
indexes = await g.sys.system.get_indexes(
    'mysql8',
    'inventory',
    table='orders',
)
# [
# { name: 'PRIMARY', key: { id: 1 }, unique: true },
# { name: 'am_ix_orders_customer_id_status_3f9a1c', key: { customer_id: 1, status: -1 }, unique: false, method: 'BTREE' },
# ]
1
2
3
4
5
6
7
8
9
$indexes = $g->sys->system->getIndexes(
    'mysql8',
    'inventory',
    table: 'orders',
);
// [
// { name: 'PRIMARY', key: { id: 1 }, unique: true },
// { name: 'am_ix_orders_customer_id_status_3f9a1c', key: { customer_id: 1, status: -1 }, unique: false, method: 'BTREE' },
// ]
var indexes = await g.Sys.System.GetIndexes(new GetIndexes
{
    Instance = "mysql8",
    Database = "inventory",
    Table = "orders",
});
// [
// { name: 'PRIMARY', key: { id: 1 }, unique: true },
// { name: 'am_ix_orders_customer_id_status_3f9a1c', key: { customer_id: 1, status: -1 }, unique: false, method: 'BTREE' },
// ]
indexes, err := g.Sys.System.GetIndexes(am.GetIndexes{
    Instance: "mysql8",
    Database: "inventory",
    Table:    "orders",
})
if err != nil {
    return nil, err
}
// [
// { name: 'PRIMARY', key: { id: 1 }, unique: true },
// { name: 'am_ix_orders_customer_id_status_3f9a1c', key: { customer_id: 1, status: -1 }, unique: false, method: 'BTREE' },
// ]
let indexes = g.sys.system.get_indexes(
    GetIndexes::default()
        .instance("mysql8")
        .database("inventory")
        .table("orders"),
)?;
// [
// { name: 'PRIMARY', key: { id: 1 }, unique: true },
// { name: 'am_ix_orders_customer_id_status_3f9a1c', key: { customer_id: 1, status: -1 }, unique: false, method: 'BTREE' },
// ]
1
2
3
4
5
6
7
8
var indexes = g.sys.system.getIndexes(new GetIndexes()
    .instance("mysql8")
    .database("inventory")
    .table("orders"));
// [
// { name: 'PRIMARY', key: { id: 1 }, unique: true },
// { name: 'am_ix_orders_customer_id_status_3f9a1c', key: { customer_id: 1, status: -1 }, unique: false, method: 'BTREE' },
// ]
val indexes = g.sys.system.getIndexes(
    GetIndexes()
        .instance("mysql8")
        .database("inventory")
        .table("orders"),
)
// [
// { name: 'PRIMARY', key: { id: 1 }, unique: true },
// { name: 'am_ix_orders_customer_id_status_3f9a1c', key: { customer_id: 1, status: -1 }, unique: false, method: 'BTREE' },
// ]

Access, headers and errors

  • Over HTTP, a system API answers only once its settings open it : TOKEN_ACCESS (the token of an API user whose group grants this system API) or IS_PUBLIC. Without settings it is NO_ACCESS : only your code (g.sys) and the admin panel reach it.
  • The settings can also keep the answer in the cache, or ask for the token of a person (authProviders). Pre and post hooks run around it, as around any API.
  • It takes the request headers and answers the envelope. 401 : no valid token, or the API is NO_ACCESS. 403 : no group grants it. 400 : the body is wrong, and the message names the key.

Related : All APIs · System API settings · System APIs from code