Struct basex::client::client::Client[][src]

pub struct Client<T> where
    T: DatabaseStream
{ connection: Connection<T, Authenticated>, }
Expand description

Represents an interface to communicate with the BaseX server. Its main purpose is to send database commands and create queries.

Start by connecting to the database using Client::connect.

Example

let mut client = Client::connect("localhost", 1984, "admin", "admin")?;

let info = client.create("a45d766")?
    .with_input("<Root><Text></Text><Lala></Lala><Papa></Papa></Root>")?;
assert!(info.starts_with("Database 'a45d766' created"));

let query = client.query("count(/Root/*)")?.without_info()?;
let mut result = String::new();
let mut response = query.execute()?;
response.read_to_string(&mut result);
assert_eq!(result, "3");

let mut query = response.close()?;
query.close()?;

Fields

connection: Connection<T, Authenticated>

Implementations

Connects and authenticates to BaseX server using TCP stream.

Example
let client = Client::connect("localhost", 1984, "admin", "admin")?;

Returns new client instance with the given connection bound to it. Works only with authenticated connections.

Typically, you only need to use this method when using a custom connection. It is used heavily in tests, for example. For regular usage, refer to the Client::connect method.

Example
let stream = TcpStream::connect("localhost:1984")?;
let connection = Connection::new(stream).authenticate("admin", "admin")?;

let client = Client::new(connection);

Executes a server command including arguments.

Returns response which can be read using the Read trait.

Example
let mut client = Client::connect("localhost", 1984, "admin", "admin")?;
let mut list = String::new();
client.execute("LIST")?.read_to_string(&mut list)?;
println!("{}", list);

Creates a new database with the specified name and, optionally, an initial input and opens it.

  • Overwrites existing database with the same name.
  • The name must be valid database name.
  • The input is a stream with valid XML.
  • More options can be controlled by setting Create Options
Example
let mut client = Client::connect("localhost", 1984, "admin", "admin")?;
client.create("boy_sminem")?.with_input("<wojak pink_index=\"69\"></wojak>")?;
client.create("bogdanoff")?.without_input()?;

Replaces resources in the currently opened database, addressed by path, with the XML document read from input, or adds new documents if no resource exists at the specified path.

Example
let mut client = Client::connect("localhost", 1984, "admin", "admin")?;
client.create("bell")?.without_input()?;
client.replace("bogdanoff", "<wojak pink_index=\"69\"></wojak>")?;

Stores a binary file from input in the currently opened database under path. Overwrites existing resource.

Example
let mut client = Client::connect("localhost", 1984, "admin", "admin")?;
let mut blob = [0 as u8, 1, 2, 3];
client.create("asylum")?.without_input()?;
client.store("bogdanoff", &mut &blob[..])?;

Adds an XML resource to the currently opened database under the specified path.

  • Keeps multiple documents with the same path. If this is unwanted, use Client::replace.
  • On the server-side if the stream is too large to be added in one go, its data structures will be cached to disk first. Caching can be enforced by turning the ADDCACHE option on.
  • The input is a stream with valid XML.
Example
let mut client = Client::connect("localhost", 1984, "admin", "admin")?;
client.create("taurus")?.without_input()?;
client.add("bogdanoff", &mut "<wojak pink_index=\"69\"></wojak>".as_bytes())?;

Creates a new query from given XQuery code.

You then need to make a statement about collecting compiler info using either with_info or without_info.

Example
let mut client = Client::connect("localhost", 1984, "admin", "admin")?;

let info = client.create("triangle")?
    .with_input("<polygon><line></line><line></line><line></line></polygon>")?;
assert!(info.starts_with("Database 'triangle' created"));

let query = client.query("count(/polygon/*)")?.without_info()?;
let mut result = String::new();
let mut response = query.execute()?;
response.read_to_string(&mut result)?;
assert_eq!(result, "3");

let mut query = response.close()?;
query.close()?;

Trait Implementations

Immutably borrows from an owned value. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.