|
@@ -1,7 +1,7 @@
|
|
use itertools::Itertools;
|
|
use itertools::Itertools;
|
|
|
|
|
|
use crate::{
|
|
use crate::{
|
|
- db::{ConnectionLease, ConnectionLeaser, StatementContext, Transaction},
|
|
|
|
|
|
+ db::{ConnectionLease, StatementContext, Transaction},
|
|
schema::{
|
|
schema::{
|
|
datum::{Datum, QueryEquivalent, QueryEquivalentList},
|
|
datum::{Datum, QueryEquivalent, QueryEquivalentList},
|
|
entity::{Entity, EntityID, EntityPart, EntityPartList},
|
|
entity::{Entity, EntityID, EntityPart, EntityPartList},
|
|
@@ -212,7 +212,7 @@ pub trait RelationInterface {
|
|
/// Attempt to connect the contextual instance to a remote instance.
|
|
/// Attempt to connect the contextual instance to a remote instance.
|
|
fn connect_to(
|
|
fn connect_to(
|
|
&self,
|
|
&self,
|
|
- lease: &ConnectionLease,
|
|
|
|
|
|
+ lease: &mut ConnectionLease,
|
|
remote_id: <Self::RemoteEntity as Entity>::ID,
|
|
remote_id: <Self::RemoteEntity as Entity>::ID,
|
|
) -> DBResult<()>
|
|
) -> DBResult<()>
|
|
where
|
|
where
|
|
@@ -221,9 +221,9 @@ pub trait RelationInterface {
|
|
let rdata = self.get_data()?;
|
|
let rdata = self.get_data()?;
|
|
let an = RelationNames::collect::<Self>(self)?;
|
|
let an = RelationNames::collect::<Self>(self)?;
|
|
|
|
|
|
- let txn = Transaction::new(lease)?;
|
|
|
|
|
|
+ let mut txn = Transaction::new(lease)?;
|
|
|
|
|
|
- base_queries::do_connect::<Self::RemoteEntity>(lease, rdata, an, remote_id)?;
|
|
|
|
|
|
+ base_queries::do_connect::<Self::RemoteEntity>(txn.lease(), rdata, an, remote_id)?;
|
|
|
|
|
|
txn.commit()
|
|
txn.commit()
|
|
}
|
|
}
|
|
@@ -231,7 +231,7 @@ pub trait RelationInterface {
|
|
/// Attempt to disconnect the contextual instance from a remote instance.
|
|
/// Attempt to disconnect the contextual instance from a remote instance.
|
|
fn disconnect_from(
|
|
fn disconnect_from(
|
|
&self,
|
|
&self,
|
|
- lease: &ConnectionLease,
|
|
|
|
|
|
+ lease: &mut ConnectionLease,
|
|
remote_id: <Self::RemoteEntity as Entity>::ID,
|
|
remote_id: <Self::RemoteEntity as Entity>::ID,
|
|
) -> DBResult<()>
|
|
) -> DBResult<()>
|
|
where
|
|
where
|
|
@@ -240,10 +240,10 @@ pub trait RelationInterface {
|
|
let rdata = self.get_data()?;
|
|
let rdata = self.get_data()?;
|
|
let an = RelationNames::collect::<Self>(self)?;
|
|
let an = RelationNames::collect::<Self>(self)?;
|
|
|
|
|
|
- let txn = Transaction::new(lease)?;
|
|
|
|
|
|
+ let mut txn = Transaction::new(lease)?;
|
|
|
|
|
|
// second, add to the relation table
|
|
// second, add to the relation table
|
|
- txn.lease().as_ref().with_prepared(
|
|
|
|
|
|
+ txn.lease().with_prepared(
|
|
hash_of(("disconnect", an.local_name, an.remote_name, an.part_name)),
|
|
hash_of(("disconnect", an.local_name, an.remote_name, an.part_name)),
|
|
|| {
|
|
|| {
|
|
format!(
|
|
format!(
|
|
@@ -272,16 +272,16 @@ pub trait RelationInterface {
|
|
/// Represents a context in which we can insert an entity type `E`.
|
|
/// Represents a context in which we can insert an entity type `E`.
|
|
pub trait Insertable<E: Entity> {
|
|
pub trait Insertable<E: Entity> {
|
|
/// Insert an entity instance and return its new ID.
|
|
/// Insert an entity instance and return its new ID.
|
|
- fn insert(&self, lease: &ConnectionLease, value: E) -> DBResult<E::ID>;
|
|
|
|
|
|
+ fn insert(&self, lease: &mut ConnectionLease, value: E) -> DBResult<E::ID>;
|
|
/// Insert an entity instance and return a [`Stored`] instance that can be used to synchronize
|
|
/// Insert an entity instance and return a [`Stored`] instance that can be used to synchronize
|
|
/// its values back into the database later.
|
|
/// its values back into the database later.
|
|
- fn insert_and_return(&self, lease: &ConnectionLease, value: E) -> DBResult<Stored<E>>;
|
|
|
|
|
|
+ fn insert_and_return(&self, lease: &mut ConnectionLease, value: E) -> DBResult<Stored<E>>;
|
|
}
|
|
}
|
|
|
|
|
|
impl<AI: RelationInterface> Insertable<AI::RemoteEntity> for AI {
|
|
impl<AI: RelationInterface> Insertable<AI::RemoteEntity> for AI {
|
|
fn insert(
|
|
fn insert(
|
|
&self,
|
|
&self,
|
|
- lease: &ConnectionLease,
|
|
|
|
|
|
+ lease: &mut ConnectionLease,
|
|
value: AI::RemoteEntity,
|
|
value: AI::RemoteEntity,
|
|
) -> DBResult<<AI::RemoteEntity as Entity>::ID>
|
|
) -> DBResult<<AI::RemoteEntity as Entity>::ID>
|
|
where
|
|
where
|
|
@@ -294,12 +294,12 @@ impl<AI: RelationInterface> Insertable<AI::RemoteEntity> for AI {
|
|
let rdata = self.get_data()?;
|
|
let rdata = self.get_data()?;
|
|
let an = RelationNames::collect::<Self>(self)?;
|
|
let an = RelationNames::collect::<Self>(self)?;
|
|
|
|
|
|
- let txn = Transaction::new(lease)?;
|
|
|
|
|
|
+ let mut txn = Transaction::new(lease)?;
|
|
|
|
|
|
// so first, into the remote table
|
|
// so first, into the remote table
|
|
- let remote_id = base_queries::insert(lease, &value)?;
|
|
|
|
|
|
+ let remote_id = base_queries::insert(txn.lease(), &value)?;
|
|
// then the relation
|
|
// then the relation
|
|
- base_queries::do_connect::<AI::RemoteEntity>(lease, rdata, an, remote_id)?;
|
|
|
|
|
|
+ base_queries::do_connect::<AI::RemoteEntity>(txn.lease(), rdata, an, remote_id)?;
|
|
|
|
|
|
txn.commit()?;
|
|
txn.commit()?;
|
|
|
|
|
|
@@ -308,7 +308,7 @@ impl<AI: RelationInterface> Insertable<AI::RemoteEntity> for AI {
|
|
|
|
|
|
fn insert_and_return(
|
|
fn insert_and_return(
|
|
&self,
|
|
&self,
|
|
- lease: &ConnectionLease,
|
|
|
|
|
|
+ lease: &mut ConnectionLease,
|
|
value: AI::RemoteEntity,
|
|
value: AI::RemoteEntity,
|
|
) -> DBResult<Stored<AI::RemoteEntity>>
|
|
) -> DBResult<Stored<AI::RemoteEntity>>
|
|
where
|
|
where
|
|
@@ -321,12 +321,12 @@ impl<AI: RelationInterface> Insertable<AI::RemoteEntity> for AI {
|
|
let rdata = self.get_data()?;
|
|
let rdata = self.get_data()?;
|
|
let an = RelationNames::collect::<Self>(self)?;
|
|
let an = RelationNames::collect::<Self>(self)?;
|
|
|
|
|
|
- let txn = Transaction::new(lease)?;
|
|
|
|
|
|
+ let mut txn = Transaction::new(lease)?;
|
|
|
|
|
|
// so first, into the remote table
|
|
// so first, into the remote table
|
|
- let remote = base_queries::insert_and_return(lease, value)?;
|
|
|
|
|
|
+ let remote = base_queries::insert_and_return(txn.lease(), value)?;
|
|
// then the relation
|
|
// then the relation
|
|
- base_queries::do_connect::<AI::RemoteEntity>(lease, rdata, an, remote.id())?;
|
|
|
|
|
|
+ base_queries::do_connect::<AI::RemoteEntity>(txn.lease(), rdata, an, remote.id())?;
|
|
|
|
|
|
txn.commit()?;
|
|
txn.commit()?;
|
|
|
|
|
|
@@ -359,13 +359,13 @@ pub trait Queryable: Clone {
|
|
/// Count all entities in the current context.
|
|
/// Count all entities in the current context.
|
|
///
|
|
///
|
|
/// Returns the number of entities.
|
|
/// Returns the number of entities.
|
|
- fn count(self, lease: &ConnectionLease) -> DBResult<usize>
|
|
|
|
|
|
+ fn count(self, lease: &mut ConnectionLease) -> DBResult<usize>
|
|
where
|
|
where
|
|
Self: Sized,
|
|
Self: Sized,
|
|
{
|
|
{
|
|
- let txn = Transaction::new(lease)?;
|
|
|
|
|
|
+ let mut txn = Transaction::new(lease)?;
|
|
struct CountTag;
|
|
struct CountTag;
|
|
- let out = txn.lease().as_ref().with_prepared(
|
|
|
|
|
|
+ let out = txn.lease().with_prepared(
|
|
std::any::TypeId::of::<(Self::StaticVersion, CountTag)>(),
|
|
std::any::TypeId::of::<(Self::StaticVersion, CountTag)>(),
|
|
|| {
|
|
|| {
|
|
self.build()
|
|
self.build()
|
|
@@ -393,13 +393,13 @@ pub trait Queryable: Clone {
|
|
Ok(out)
|
|
Ok(out)
|
|
}
|
|
}
|
|
/// Get all entities in the current context.
|
|
/// Get all entities in the current context.
|
|
- fn get(self, lease: &ConnectionLease) -> DBResult<Self::OutputContainer>
|
|
|
|
|
|
+ fn get(self, lease: &mut ConnectionLease) -> DBResult<Self::OutputContainer>
|
|
where
|
|
where
|
|
Self: Sized,
|
|
Self: Sized,
|
|
{
|
|
{
|
|
- let txn = Transaction::new(lease)?;
|
|
|
|
|
|
+ let mut txn = Transaction::new(lease)?;
|
|
struct GetTag;
|
|
struct GetTag;
|
|
- let out = txn.lease().as_ref().with_prepared(
|
|
|
|
|
|
+ let out = txn.lease().with_prepared(
|
|
std::any::TypeId::of::<(Self::StaticVersion, GetTag)>(),
|
|
std::any::TypeId::of::<(Self::StaticVersion, GetTag)>(),
|
|
|| self.build().assemble(),
|
|
|| self.build().assemble(),
|
|
|mut ctx| {
|
|
|mut ctx| {
|
|
@@ -416,14 +416,14 @@ pub trait Queryable: Clone {
|
|
/// Get IDs of all entities in the current context.
|
|
/// Get IDs of all entities in the current context.
|
|
fn get_ids(
|
|
fn get_ids(
|
|
self,
|
|
self,
|
|
- lease: &ConnectionLease,
|
|
|
|
|
|
+ lease: &mut ConnectionLease,
|
|
) -> DBResult<<Self::OutputContainer as OutputContainer<Self::EntityOutput>>::IDContainer>
|
|
) -> DBResult<<Self::OutputContainer as OutputContainer<Self::EntityOutput>>::IDContainer>
|
|
where
|
|
where
|
|
Self: Sized,
|
|
Self: Sized,
|
|
{
|
|
{
|
|
- let txn = Transaction::new(lease)?;
|
|
|
|
|
|
+ let mut txn = Transaction::new(lease)?;
|
|
struct GetIDTag;
|
|
struct GetIDTag;
|
|
- let out = txn.lease().as_ref().with_prepared(
|
|
|
|
|
|
+ let out = txn.lease().with_prepared(
|
|
std::any::TypeId::of::<(Self::StaticVersion, GetIDTag)>(),
|
|
std::any::TypeId::of::<(Self::StaticVersion, GetIDTag)>(),
|
|
|| {
|
|
|| {
|
|
self.build()
|
|
self.build()
|
|
@@ -447,13 +447,13 @@ pub trait Queryable: Clone {
|
|
Ok(out)
|
|
Ok(out)
|
|
}
|
|
}
|
|
/// Delete all entities in the current context.
|
|
/// Delete all entities in the current context.
|
|
- fn delete(self, lease: &ConnectionLease) -> DBResult<()>
|
|
|
|
|
|
+ fn delete(self, lease: &mut ConnectionLease) -> DBResult<()>
|
|
where
|
|
where
|
|
Self: Sized,
|
|
Self: Sized,
|
|
{
|
|
{
|
|
- let txn = Transaction::new(lease)?;
|
|
|
|
|
|
+ let mut txn = Transaction::new(lease)?;
|
|
struct DeleteTag;
|
|
struct DeleteTag;
|
|
- txn.lease().as_ref().with_prepared(
|
|
|
|
|
|
+ txn.lease().with_prepared(
|
|
std::any::TypeId::of::<(Self::StaticVersion, DeleteTag)>(),
|
|
std::any::TypeId::of::<(Self::StaticVersion, DeleteTag)>(),
|
|
|| {
|
|
|| {
|
|
format!(
|
|
format!(
|
|
@@ -480,13 +480,13 @@ pub trait Queryable: Clone {
|
|
}
|
|
}
|
|
|
|
|
|
/// Delete all entities in the current context and return them
|
|
/// Delete all entities in the current context and return them
|
|
- fn remove(self, lease: &ConnectionLease) -> DBResult<Self::OutputContainer>
|
|
|
|
|
|
+ fn remove(self, lease: &mut ConnectionLease) -> DBResult<Self::OutputContainer>
|
|
where
|
|
where
|
|
Self: Sized,
|
|
Self: Sized,
|
|
{
|
|
{
|
|
- let txn = Transaction::new(lease)?;
|
|
|
|
|
|
+ let mut txn = Transaction::new(lease)?;
|
|
struct DeleteTag;
|
|
struct DeleteTag;
|
|
- let out = txn.lease().as_ref().with_prepared(
|
|
|
|
|
|
+ let out = txn.lease().with_prepared(
|
|
std::any::TypeId::of::<(Self::StaticVersion, DeleteTag)>(),
|
|
std::any::TypeId::of::<(Self::StaticVersion, DeleteTag)>(),
|
|
|| {
|
|
|| {
|
|
format!(
|
|
format!(
|