MoveDatabase

MoveDatabase( from, to )
MoveDatabase( from, to )
MoveDatabase( from, to )
MoveDatabase( from, to )
move_database( from, to )
MoveDatabase( from, to )

Description

The MoveDatabase function moves the from database into the to database, making from a child database of to.

You must use an admin key that has access to the from database or MoveDatabase fails.

Parameters

Argument Type Definition and Requirements

from

A database ref for the database to be moved.

to

A database ref for the new parent database of from.

Returns

A database ref for the moved database.

Examples

The following example creates the stamps database and the hobbies database, and then moves the stamps database into the hobbies database:

Field<RefV> refField = Field.At("ref").To<RefV>();

Value stamps = await client.Query(
    CreateDatabase(Obj("name", "stamps"))
);
Value hobbies = await client.Query(
    CreateDatabase(Obj("name", "hobbies"))
);
Value result = await client.Query(
    MoveDatabase(stamps.Get(refField), hobbies.Get(refField))
);
ObjectV(ref: RefV(id = "stamps", collection = RefV(id = "databases"), database = RefV(id = "hobbies", collection = RefV(id = "databases"))),ts: LongV(1603756596430000),name: StringV(stamps),global_id: StringV(yx1edqz3rydyy))
var refField = f.ObjKey("ref")
var stampsRef, hobbiesRef f.RefV

stamps, err := client.Query(
	f.CreateDatabase(f.Obj{"name": "stamps"}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
}

_ = stamps.At(refField).Get(&stampsRef)

hobbies, err := client.Query(
	f.CreateDatabase(f.Obj{"name": "hobbies"}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
}

_ = hobbies.At(refField).Get(&hobbiesRef)

result, err := client.Query(
	f.MoveDatabase(stampsRef, hobbiesRef))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[global_id:yx18twpc4ydyy name:stamps ref:{stamps 0xc0001566f0 0xc0001566f0 0xc000156750} ts:1603747252180000]
Value stamps = client.query(
    CreateDatabase(Obj("name", Value("stamps")))
).get();
Value hobbies = client.query(
    CreateDatabase(Obj("name", Value("hobbies")))
).get();
System.out.println(
    client.query(
        MoveDatabase(
            stamps.get(Field.at("ref")),
            hobbies.get(Field.at("ref"))
        )
    ).get()
);
{ref: ref(id = "stamps", collection = ref(id = "databases"), database = ref(id = "hobbies", collection = ref(id = "databases"))), ts: 1593466725930000, name: "stamps", global_id: "yq9n3nh8hybyy"}
Promise.all([
  client.query(
    q.CreateDatabase({ name: 'stamps' })
  ),
  client.query(
    q.CreateDatabase({ name: 'hobbies' })
  ),
])
.then(([stamps, hobbies]) => client.query(
  q.MoveDatabase(stamps.ref, hobbies.ref)
))
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{
  ref: Database("stamps", Database("hobbies")),
  ts: 1592113609950000,
  name: 'stamps',
  global_id: 'yqh1r886wybyy'
}
stamps = client.query(
  q.create_database({"name": "stamps"})
)
hobbies = client.query(
  q.create_database({"name": "hobbies"})
)
result = client.query(
  q.move_database(stamps["ref"], hobbies["ref"])
)
print(result)
{'ref': Ref(id=stamps, collection=Ref(id=databases), database=Ref(id=hobbies, collection=Ref(id=databases))), 'ts': 1592874958520000, 'name': 'stamps', 'global_id': 'yq79oce4qybyy'}
  val stamps = Await.result(client.query(
    CreateDatabase(Obj("name" -> "stamps"))
  ), 5.seconds)
  val hobbies = Await.result(client.query(
    CreateDatabase(Obj("name" -> "hobbies"))
  ), 5.seconds)
  println(Await.result(client.query(
      MoveDatabase(stamps("ref").get, hobbies("ref").get)
  ), 5.seconds))
{ref: ref(id = "stamps", collection = ref(id = "databases"), database = ref(id = "hobbies", collection = ref(id = "databases"))), ts: 1570139962250000, name: "stamps"}

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!