v0.4.0
Blog Post: https://bonsaidb.io/blog/bonsaidb-v0-4-0/
All commits since last release: v0.3.0...v0.4.0
Breaking Changes
The blog post has a section discussing updating existing projects. If you have any issues upgrading, don't hesitate to open an issue, a discussion, or reach out on Discord.
-
BonsaiDb now has both an async interface as well as a blocking interface. This
has caused significant changes, but they can be summarized simply:-
Connection-related async-compatible traits have had the
Async
prefix added
to them.Blocking Async Connection AsyncConnection StorageConnection AsyncStorageConnection PubSub AsyncPubSub Subscriber AsyncSubscriber KeyValue AsyncKeyValue LowLevelConnection AsyncLowLevelConnection -
Functions that take parameters of the above traits now are offered in pairs:
a blocking function and an async function with "_async" at the end of the
name. For example,SerializedCollection::get()
is the blocking version of
SerializedCollection::get_async()
. -
For
bonsaidb-local
, theDatabase
andStorage
types are now blocking
implementations. Under the hood, BonsaiDb previously used
tokio::task::spawn_blocking()
to wrap calls to the database in an async
API. New types,AsyncDatabase
andAsyncStorage
have been added that
provide the previous behavior. The types can be converted between each other
using helpers as/into/to_blocking/async available on each type.These changes allow
bonsaidb-local
to be compiled without Tokio. To enable
tokio, enable featureasync
if usingbonsaidb-local
directly, or enable
featurelocal-async
when using thebonsaidb
crate. -
For
bonsaidb-server
, it still uses networking driven by Tokio.
Server
/CustomServer
implementAsyncStorageConnection
, andServer
can
convert toStorage
via theFrom
trait for synchronous database access. -
For
bonsaidb-client
,Client
implements bothAsyncStorageConnection
and
StorageConnection
and is safe for use in both synchronous and asynchronous
contexts. In WASM,Client
only implementsAsyncStorageConnection
. For
all other platforms, theClient
builder supports specifying the Tokio
runtime handle if needed. Otherwise, the current runtime will be used or a
default runtime will be created automatically if unavailable.
-
-
Connection::query_with_docs
/Connection::query_with_connection_docs
now
verify the user has permission toDocumentAction::Get
. This allows schema
authors to allow querying views without allowing the documents themselves to
be fetched. -
ViewAction::DeleteDocs
has been removed. Delete docs is now composed of two
permissions checks:ViewAction::Query
to retrieve the list of documents to
delete, andDocumentAction::Delete
for each document retrieved. This ensures
if permission is denied to delete a specific document, it still cannot be
deleted throughdelete_docs()
. -
All APIs have had their
limit
parameters changed fromusize
tou32
.
Sinceusize
is platform-dependent, picking a fixed-width type is more
appropriate. -
CustomApi
has been renamed toApi
and changed significantly.On the Server,
Api
s are registered on theServerConfiguration
. TheApi
implementor is treated as the "request" type and is whatClient
s send to the
Server. TheApi::Response
type is what the Server sends to theClient
.
Out-of-band responses can still be delivered.On the Client,
Api
s can simply be used without any extra steps. If you
expect out-of-band responses, callbacks can be registered when building the
client.Internally, all BonsaiDb APIs have been refactored to use this -- there is no
distinction. -
The
multiuser
feature flag has been removed. In the end this caused a lot of
needless conditional compilation for removing a single lightweight dependency. -
User::assume_identity
andRole::assume_identity
allow assuming the
identity of a user or role by their unique ID or name. The connection must be
permitted with the newly addedServerAction::AssumeIdentity
for the
appropriate resource name (user_resource_name
orrole_resource_name
). -
StorageConnection::authenticate
andStorageConnection::assume_identity
both return a new instance with the new authentication. This enables
authenticating as multiple roles with the same underlying storage connection.StorageConnection::session()
is a new function that returns the current
Session
, if one exists. This new type contains information about any
currently authenticated identity, the unique id of the session, and the
current effective permissions.This release note applies equally to
AsyncStorageConnection
. -
LowLevelConnection
andAsyncLowLevelConnection
have been added to group
functionality that is not generally meant for the average user to utilize. The
methods that were documented as low-level inConnection
/AsyncConnection
have been moved to this trait. Additionally, new methods that allow performing
operations without the generic types have been added to this trait. This
functionality is what will be useful in providing applications that can
interact with BonsaiDb without having the Schema definitions available. -
PubSub
/AsyncPubSub
now allows anySerialize
implementation to be used as
the topic parameter. New methodspublish_bytes
andpublish_bytes_to_all
have been added enabling publishing raw payloads. -
CollectionName
/SchemaName
have had common methods extracted to a trait,
Qualified
. This was part of a refactoring to share code between these two
types and the newly introducedApiName
type. -
BackupLocation
andVaultKeyStorage
have been changed to blocking traits.
bonsaidb-keystorage-s3
wraps a tokio Runtime handle as the AWS SDK requires
Tokio. -
ServerConfiguration
now takes aBackend
generic parameter, which must
match theCustomServer
being created. In general the Rust compiler should be
able to infer this type based on usage, and therefore shouldn't be a breaking
change to many people. -
The
Backend
trait now has an associatedError
type, which allows for
custom error types to be used. When an error occurs during initialization, it
is returned. Currently, errors that are returned during client connection
handling are printed usinglog::error
and ignored. -
Key
has had its encoding functionality moved to a new trait,KeyEncoding
.
KeyEncoding
has been implemented for borrowed representations ofKey
types.This change allows all view query and collection access to utilize borrowed
versions of their key types. For example, if a View'sKey
type isString
,
it is now possible to query the view using an&str
parameter.
Added
-
Range::default()
now returns an unbounded range, andBound::default()
returnsBound::Unbounded
. -
Range
now has several builder-pattern style methods to help construct
ranges. In general, users should simply use the built-in range operators
(..
,start..
,start..end
,start..=end
), as they are able to represent
nearly every range pattern. The built-in range operators do not support
specifying an excluded start bound, while the new methodRange::after
allows
setting an excluded start bound. -
#215:
StorageConnection::delete_user()
is a new function that allows
deleting a user by name or id. Deleting a user is permitted with the
ServerAction::DeleteUser
action. -
bonsaidb_core::key::encode_composite_field
and
bonsaidb_core::key::decode_composite_field
have been added which allow
building more complexKey
implementations that are composed of multiple
fields. These functions are what theKey
implementation for tuples is
powered by. -
Key
is now implemented for[u8; N]
. -
#221:
headers()
has been as a function to all collection list
builders, enabling querying just the headers of a document. -
Transaction
now hasapply()
andapply_async()
, which the higher-level
API toLowLevelConnection::apply_transaction
. -
ArgonConfiguration
can now be specified when building
StorageConfiguration
/ServerConfiguration
usingBuilder::argon
. -
SystemTime
andDuration
now haveKey
implementations. -
bonsaidb_core::key::time
has been added which contains a wide array of types
that enable storing timestamps and durations with limited resolution, powered
by variable integer encoding to reduce the number of bytes needed to encode
the values.These types are powered by two traits:
TimeResolution
andTimeEpoch
. Using
these traits, theLimitedResolutionDuration
andLimitedResolutionTimestamp
types can be used for completely custom resolutions (e.g., 15 minutes) and
epochs (the base moment in time to store the limited resolution relative to).By constraining the resolution and using an epoch that is closer to the
average timestamp being stored, we can reduce the number of bytes required to
represent the values from 12 bytes to significantly fewer.These type aliases have been added in these three categories:
- Durations:
Weeks
,Days
,Hours
,Minutes
,Seconds
,Milliseconds
,
Microseconds
, andNanoseconds
. - Timestamps relative to the Unix Epoch (Jan 1, 1970 00:00:00 UTC):
WeeksSinceUnixEpoch
,DaysSinceUnixEpoch
, ... - Timestamps relative to the Bonsai Epoch (Mar 20, 2031 04:31:47 UTC):
TimestampAsWeeks
,TimestampAsDays
, ...
- Durations:
-
Backend::configure()
is a new function that allows aBackend
to set
configuration options onServerConfiguration
before the server is
initialized. This is a good location forBackend
s to define theirApi
s and
Schema
s.
Changed
- Counting a list of documents now uses
reduce()
in Nebari, a new feature that
allows aggregating the embedded statistics without traversing the entire tree.
The net result is that retrieving a Collection's count should be near instant
and returning the count of a range of keys should be very fast as well. StorageConnection::create_database
/AsyncStorageConnection::create_database
now returns the newly created database.
Fixed
- Defining multiple views with the same name for the same collection will now
return an error.