Struct Builder

Source
pub struct Builder { /* private fields */ }
Expand description

A builder used to create connections.

Implementations§

Source§

impl Builder

Source

pub async fn from_env() -> Result<Builder, Error>

Initializes a Builder using environment variables or project config.

Source

pub async fn read_project( &mut self, override_dir: Option<&Path>, search_parents: bool, ) -> Result<&mut Self, Error>

Reads the project config if it exists.

Projects are initialized using the command-line tool:

edgedb project init

Linking to an already running EdgeDB is also possible:

edgedb project init --link

Returns a boolean value indicating whether the project was found.

Source

pub fn is_initialized(&self) -> bool

Indicates whether credentials are set for this builder.

Source

pub async fn read_env_vars(&mut self) -> Result<&mut Self, Error>

Read environment variables and set respective configuration parameters.

This function initializes the builder if one of the following is set:

  • EDGEDB_CREDENTIALS_FILE
  • EDGEDB_INSTANCE
  • EDGEDB_DSN
  • EDGEDB_HOST or EDGEDB_PORT

If it finds one of these then it will reset all previously set credentials.

If one of the following are set:

  • EDGEDB_DATABASE
  • EDGEDB_USER
  • EDGEDB_PASSWORD

Then the value of that environment variable will be used to set just the parameter matching that environment variable.

The insecure_dev_mode and connection parameters are never modified by this function for now.

Source

pub fn read_extra_env_vars(&mut self) -> Result<&mut Self, Error>

Read environment variables that aren’t credentials

Source

pub fn credentials( &mut self, credentials: &Credentials, ) -> Result<&mut Self, Error>

Set all credentials.

This marks the builder as initialized.

Source

pub async fn read_instance(&mut self, name: &str) -> Result<&mut Self, Error>

Read credentials from the named instance.

Named instances are created using the command-line tool, either directly:

edgedb instance create <name>

or when initializing a project:

edgedb project init

In the latter case you should use read_project() instead if possible.

This will mark the builder as initialized (if reading is successful) and overwrite all credentials. However, insecure_dev_mode, pools sizes, and timeouts are kept intact.

Source

pub async fn read_credentials( &mut self, path: impl AsRef<Path>, ) -> Result<&mut Self, Error>

Read credentials from a file.

This will mark the builder as initialized (if reading is successful) and overwrite all credentials. However, insecure_dev_mode, pools sizes, and timeouts are kept intact.

Source

pub async fn read_dsn(&mut self, dsn: &str) -> Result<&mut Self, Error>

Initialize credentials using data source name (DSN).

DSN’s that EdgeDB like are URL with egdgedb::/scheme:

edgedb://user:secret@localhost:5656/

All the credentials can be specified using a DSN, although parsing a DSN may also lead to reading of environment variables (if query arguments of the for *_env are specified) and local files (for query arguments named *_file).

This will mark the builder as initialized (if reading is successful) and overwrite all the credentials. However, insecure_dev_mode, pools sizes, and timeouts are kept intact.

Source

pub fn uninitialized() -> Builder

Creates a new builder that has to be intialized by calling some methods.

This is only useful if you have connections to multiple unrelated databases, or you want to have total control of the database initialization process.

Usually, Builder::from_env() should be used instead.

Source

pub fn as_credentials(&self) -> Result<Credentials, Error>

Extract credentials from the Builder so they can be saved as JSON.

Source

pub fn get_host(&self) -> &str

Get the host this builder is configured to connect to.

For unix-socket-configured builder (only if admin_socket feature is enabled) returns “localhost”

Source

pub fn get_port(&self) -> u16

Get the port this builder is configured to connect to.

Source

pub fn host_port( &mut self, host: Option<impl Into<String>>, port: Option<u16>, ) -> &mut Self

Initialize credentials using host/port data.

If either of host or port is None, they are replaced with the default of localhost and 5656 respectively.

This will mark the builder as initialized and overwrite all the credentials. However, insecure_dev_mode, pools sizes, and timeouts are kept intact.

Source

pub fn get_user(&self) -> &str

Get the user name for SCRAM authentication.

Source

pub fn user(&mut self, user: impl Into<String>) -> &mut Self

Set the user name for SCRAM authentication.

Source

pub fn password(&mut self, password: impl Into<String>) -> &mut Self

Set the password for SCRAM authentication.

Source

pub fn database(&mut self, database: impl Into<String>) -> &mut Self

Set the database name.

Source

pub fn get_database(&self) -> &str

Get the database name.

Source

pub fn wait_until_available(&mut self, time: Duration) -> &mut Self

Set the time to wait for the database server to become available.

This works by ignoring certain errors known to happen while the database is starting up or restarting (e.g. “connection refused” or early “connection reset”).

Note: the amount of time establishing a connection can take is the sum of wait_until_available plus connect_timeout

Source

pub fn connect_timeout(&mut self, timeout: Duration) -> &mut Self

A timeout for a single connect attempt.

The default is 10 seconds. A subsecond timeout should be fine for most networks. However, in some cases this can be much slower. That’s because this timeout includes authentication, during which:

  • The password is checked (slow by design).
  • A compiler process is launched (slow now, may be optimized later).

So in a concurrent case on slower VMs (such as CI with parallel tests), 10 seconds is more reasonable default.

The wait_until_available setting should be larger than this value to allow multiple attempts.

Note: the amount of time establishing a connection can take is the sum of wait_until_available plus connect_timeout

Source

pub fn pem_certificates( &mut self, cert_data: &String, ) -> Result<&mut Self, Error>

Set the allowed certificate as a PEM file.

Source

pub fn tls_security(&mut self, value: TlsSecurity) -> &mut Self

Updates the client TLS security mode.

By default, the certificate chain is always verified; but hostname verification is disabled if configured to use only a specific certificate, and enabled if root certificates are used.

Source

pub fn insecure_dev_mode(&mut self, value: bool) -> &mut Self

Enables insecure dev mode.

This disables certificate validation entirely.

Source

pub fn display_addr<'x>(&'x self) -> impl Display + 'x

A displayable form for an address this builder will connect to

Source

pub fn build(&self) -> Result<Config, Error>

Build connection and pool configuration object

Source

pub fn max_connections(&mut self, value: usize) -> &mut Self

Set the maximum number of underlying database connections.

Trait Implementations§

Source§

impl Clone for Builder

Source§

fn clone(&self) -> Builder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Builder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

fn clone_any(&self) -> Box<dyn CloneAny>

Source§

fn clone_any_send(&self) -> Box<dyn CloneAny + Send>
where T: Send,

Source§

fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync>
where T: Sync,

Source§

fn clone_any_send_sync(&self) -> Box<dyn CloneAny + Sync + Send>
where T: Send + Sync,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DebugAny for T
where T: Any + Debug,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> UnsafeAny for T
where T: Any,