Indexes

Indexes( [database] )
Indexes( [database] )
Indexes( [database] )
Indexes( [database] )
indexes( [database] )
Indexes( [database] )

Description

The Indexes function, when executed with Paginate, returns an array of References for all indexes in the specified child database. If a child database is not specified, the returned index references all belong to the current database.

When a child database is specified, an admin key must be used to call Indexes (server or client keys, or ABAC tokens, cannot be used to access a child database).

Parameters

Argument Type Definition and Requirements

database

Optional - A reference to a child database. If not specified, the current database is used.

Returns

A Set Reference for the available indexes in the specified child database (or the current database if database is not specified).

Examples

The following query gets the References to all (up to the pagination limit) indexes in the current database:

try
{
    Value result = await client.Query(
        Paginate(Indexes())
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(data: Arr(RefV(id = "spells_by_element", collection = RefV(id = "indexes")), RefV(id = "spellbooks_by_owner", collection = RefV(id = "indexes")), RefV(id = "spells_by_spellbook", collection = RefV(id = "indexes")), RefV(id = "spells_by_element_and_name", collection = RefV(id = "indexes")), RefV(id = "elements_of_spells", collection = RefV(id = "indexes")), RefV(id = "letters", collection = RefV(id = "indexes")), RefV(id = "people_by_age_first", collection = RefV(id = "indexes")), RefV(id = "people_by_last_first", collection = RefV(id = "indexes")), RefV(id = "users_by_email", collection = RefV(id = "indexes")), RefV(id = "products_by_customer", collection = RefV(id = "indexes")), RefV(id = "products_by_store", collection = RefV(id = "indexes")), RefV(id = "inventory_by_product", collection = RefV(id = "indexes")), RefV(id = "products_by_prices_high_to_low", collection = RefV(id = "indexes")), RefV(id = "products_by_prices_low_to_high", collection = RefV(id = "indexes"))))
result, err := client.Query(
	f.Paginate(f.Indexes()))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[data:[{spells_by_element 0xc00014a180 0xc00014a180 <nil>} {spellbooks_by_owner 0xc00014a270 0xc00014a270 <nil>} {spells_by_spellbook 0xc00014a360 0xc00014a360 <nil>} {spells_by_element_and_name 0xc00014a450 0xc00014a450 <nil>} {elements_of_spells 0xc00014a540 0xc00014a540 <nil>} {letters 0xc00014a630 0xc00014a630 <nil>} {people_by_age_first 0xc0000b9140 0xc0000b9140 <nil>} {people_by_last_first 0xc0000b9230 0xc0000b9230 <nil>} {users_by_email 0xc0000b9320 0xc0000b9320 <nil>} {products_by_customer 0xc0000b9410 0xc0000b9410 <nil>} {products_by_store 0xc0000b9500 0xc0000b9500 <nil>} {inventory_by_product 0xc0000b95f0 0xc0000b95f0 <nil>} {products_by_prices_high_to_low 0xc0000b96e0 0xc0000b96e0 <nil>} {products_by_prices_low_to_high 0xc0000b97d0 0xc0000b97d0 <nil>}]]
System.out.println(
    client.query(
        Paginate(Indexes())
    ).get());
{data: [ref(id = "spells_by_element", collection = ref(id = "indexes")), ref(id = "spellbooks_by_owner", collection = ref(id = "indexes")), ref(id = "spells_by_spellbook", collection = ref(id = "indexes")), ref(id = "spells_by_element_and_name", collection = ref(id = "indexes")), ref(id = "elements_of_spells", collection = ref(id = "indexes")), ref(id = "letters", collection = ref(id = "indexes")), ref(id = "people_by_age_first", collection = ref(id = "indexes")), ref(id = "people_by_last_first", collection = ref(id = "indexes")), ref(id = "users_by_email", collection = ref(id = "indexes")), ref(id = "products_by_customer", collection = ref(id = "indexes")), ref(id = "products_by_store", collection = ref(id = "indexes")), ref(id = "inventory_by_product", collection = ref(id = "indexes")), ref(id = "products_by_prices_high_to_low", collection = ref(id = "indexes")), ref(id = "products_by_prices_low_to_high", collection = ref(id = "indexes"))]}
client.query(
  q.Paginate(q.Indexes())
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{
  data: [
    Index("spells_by_element"),
    Index("spellbooks_by_owner"),
    Index("spells_by_spellbook"),
    Index("spells_by_element_and_name"),
    Index("elements_of_spells"),
    Index("letters"),
    Index("people_by_age_first"),
    Index("people_by_last_first"),
    Index("users_by_email"),
    Index("products_by_customer"),
    Index("products_by_store"),
    Index("inventory_by_product"),
    Index("products_by_prices_high_to_low"),
    Index("products_by_prices_low_to_high")
  ]
}
result = client.query(
  q.paginate(q.indexes())
)
print(result)
{'data': [Ref(id=spells_by_element, collection=Ref(id=indexes)), Ref(id=spellbooks_by_owner, collection=Ref(id=indexes)), Ref(id=spells_by_spellbook, collection=Ref(id=indexes)), Ref(id=spells_by_element_and_name, collection=Ref(id=indexes)), Ref(id=elements_of_spells, collection=Ref(id=indexes)), Ref(id=letters, collection=Ref(id=indexes)), Ref(id=people_by_age_first, collection=Ref(id=indexes)), Ref(id=people_by_last_first, collection=Ref(id=indexes)), Ref(id=users_by_email, collection=Ref(id=indexes)), Ref(id=products_by_customer, collection=Ref(id=indexes)), Ref(id=products_by_store, collection=Ref(id=indexes)), Ref(id=inventory_by_product, collection=Ref(id=indexes)), Ref(id=products_by_prices_high_to_low, collection=Ref(id=indexes)), Ref(id=products_by_prices_low_to_high, collection=Ref(id=indexes))]}
try {
  println(Await.result(
    client.query(Paginate(Indexes())),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
{data: [ref(id = "spells_by_element", collection = ref(id = "indexes")), ref(id = "spellbooks_by_owner", collection = ref(id = "indexes")), ref(id = "spells_by_spellbook", collection = ref(id = "indexes")), ref(id = "spells_by_element_and_name", collection = ref(id = "indexes")), ref(id = "elements_of_spells", collection = ref(id = "indexes")), ref(id = "letters", collection = ref(id = "indexes")), ref(id = "people_by_age_first", collection = ref(id = "indexes")), ref(id = "people_by_last_first", collection = ref(id = "indexes")), ref(id = "users_by_email", collection = ref(id = "indexes")), ref(id = "products_by_customer", collection = ref(id = "indexes")), ref(id = "products_by_store", collection = ref(id = "indexes")), ref(id = "inventory_by_product", collection = ref(id = "indexes")), ref(id = "products_by_prices_high_to_low", collection = ref(id = "indexes")), ref(id = "products_by_prices_low_to_high", collection = ref(id = "indexes"))]}

The following query demonstrates what happens when no indexes exist:

try
{
    Value result = await client.Query(
        Paginate(Indexes())
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(data: Arr())
result, err := client.Query(
	f.Paginate(f.Indexes()))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[data:[]]
System.out.println(
    client.query(
        Paginate(Indexes())
    ).get());
{data: []}
client.query(
  q.Paginate(q.Indexes())
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{ data: [] }
result = client.query(
  q.paginate(q.indexes())
)
print(result)
{'data': []}
try {
  println(Await.result(
    client.query(
      Paginate(Indexes())
    ),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
{data: []}

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!