Database

Database( name, [database] )
Database( name )
ScopedDatabase( name, database )
Database( 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).

Parameters

Argument Type Definition and Requirements

name

The name of a database.

database

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.

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>}
    System.out.println(
        client.query(
            Database("prydain")
        ).get());
    ref(id = "prydain", collection = ref(id = "databases"))
    client.query(
      q.Database('prydain')
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error('Error: %s', err))
    Database("prydain")
    result = client.query(
      q.database("prydain")
    )
    print(result)
    Ref(id=prydain, collection=Ref(id=databases))
    try {
      println(Await.result(
        client.query(Database("prydain")),
        5.seconds
      ))
    } catch {
      case unknown: Throwable => println("Error: " + unknown.getMessage())
    }
    ref(id = "prydain", collection = ref(id = "databases"))
  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}
    System.out.println(
        client.query(
            Database("grandchild_db", Database("prydain"))
        ).get());
    ref(id = "grandchild_db", collection = ref(id = "databases"), database = ref(id = "prydain", collection = ref(id = "databases")))
    client.query(
      q.Database('grandchild_db', q.Database('prydain'))
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error('Error: %s', err))
    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)))
    try {
      println(Await.result(
        client.query(Database("grandchild_db", Database("prydain"))),
        5.seconds
      ))
    } catch {
      case unknown: Throwable => println("Error: " + unknown.getMessage())
    }
    ref(id = "grandchild_db", collection = ref(id = "databases"), database = ref(id = "prydain", collection = ref(id = "databases")))

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!