Database

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

Database( name, [database] )
Database( name )
ScopedDatabase( name, database )
Database( name, [database] )
database( name, [database] )
Database( name, [database] )

Description

The Database function returns a valid Reference for the specified child database name, within the specified child database. If a child database is not specified, the returned database reference belongs to the current database.

The Database function only looks up child databases, so finding a database using this function requires you to use an admin key for the current database (a server or client key cannot be used to access any child database).

It is not possible to access a parent or peer database with this function. To access databases outside of the current database, use the Fauna Dashboard.

Parameters

Parameter Type Definition and Requirements

name

String

The name of a database.

database

Reference

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

A Reference to a child database.

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

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

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

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

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

Returns

A reference to a child database with the specified name, in the specified child database (or the current database is database is not specified).

Examples

  1. The following query gets a Reference to the database named "prydain" within the current database:

    try
    {
        Value result = await client.Query(
            Database("prydain")
        );
        Console.WriteLine(result);
    }
    catch (Exception e)
    {
        Console.WriteLine($"ERROR: {e.Message}");
    }
    RefV(id = "prydain", collection = RefV(id = "databases"))
    result, err := client.Query(
    	f.Database("prydain"))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    {prydain 0xc000162090 0xc000162090 <nil>}
    client.query(
      q.Database('prydain')
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error(
      'Error: [%s] %s: %s',
      err.name,
      err.message,
      err.errors()[0].description,
    ))
    Database("prydain")
    result = client.query(
      q.database("prydain")
    )
    print(result)
    Ref(id=prydain, collection=Ref(id=databases))
    Database('prydain')
    Database("prydain")
    Query metrics:
    •    bytesIn:  22

    •   bytesOut:  79

    • computeOps:   1

    •    readOps:   0

    •   writeOps:   0

    •  readBytes:  62

    • writeBytes:   0

    •  queryTime: 9ms

    •    retries:   0

  2. The following query gets a Reference to the database named "grandchild_db" within the child database named "prydain":

    try
    {
        Value result = await client.Query(
            Database("grandchild_db", Database("prydain"))
        );
        Console.WriteLine(result);
    }
    catch (Exception e)
    {
        Console.WriteLine($"ERROR: {e.Message}");
    }
    RefV(id = "grandchild_db", collection = RefV(id = "databases"), database = RefV(id = "prydain", collection = RefV(id = "databases")))
    result, err := client.Query(
    	f.ScopedDatabase("grandchild_db", f.Database("prydain")))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    {grandchild_db 0xc00008e2d0 0xc00008e2d0 0xc00008e330}
    client.query(
      q.Database('grandchild_db', q.Database('prydain'))
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error(
      'Error: [%s] %s: %s',
      err.name,
      err.message,
      err.errors()[0].description,
    ))
    Database("grandchild_db", Database("prydain"))
    result = client.query(
      q.database("grandchild_db", q.database("prydain"))
    )
    print(result)
    Ref(id=grandchild_db, collection=Ref(id=databases), database=Ref(id=prydain, collection=Ref(id=databases)))
    Database('grandchild_db', Database('prydain'))
    Database("grandchild_db", Database("prydain"))
    Query metrics:
    •    bytesIn:   59

    •   bytesOut:  163

    • computeOps:    1

    •    readOps:    0

    •   writeOps:    0

    •  readBytes:  179

    • writeBytes:    0

    •  queryTime: 51ms

    •    retries:    0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!