mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 02:46:43 +00:00
Upgrade SeaORM to latest version, also upgrade sqlite bindings, rustqlite, and remove SeaQuery
co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
32c4138758
commit
6007c8705c
12 changed files with 460 additions and 290 deletions
654
Cargo.lock
generated
654
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -105,6 +105,7 @@ rand = { version = "0.8.5" }
|
||||||
refineable = { path = "./crates/refineable" }
|
refineable = { path = "./crates/refineable" }
|
||||||
regex = { version = "1.5" }
|
regex = { version = "1.5" }
|
||||||
rust-embed = { version = "8.0", features = ["include-exclude"] }
|
rust-embed = { version = "8.0", features = ["include-exclude"] }
|
||||||
|
rusqlite = { version = "0.29.0", features = ["blob", "array", "modern_sqlite"] }
|
||||||
schemars = { version = "0.8" }
|
schemars = { version = "0.8" }
|
||||||
serde = { version = "1.0", features = ["derive", "rc"] }
|
serde = { version = "1.0", features = ["derive", "rc"] }
|
||||||
serde_derive = { version = "1.0", features = ["deserialize_in_place"] }
|
serde_derive = { version = "1.0", features = ["deserialize_in_place"] }
|
||||||
|
|
|
@ -27,7 +27,7 @@ log.workspace = true
|
||||||
parse_duration = "2.1.1"
|
parse_duration = "2.1.1"
|
||||||
tiktoken-rs = "0.5.0"
|
tiktoken-rs = "0.5.0"
|
||||||
matrixmultiply = "0.3.7"
|
matrixmultiply = "0.3.7"
|
||||||
rusqlite = { version = "0.27.0", features = ["blob", "array", "modern_sqlite"] }
|
rusqlite = { version = "0.29.0", features = ["blob", "array", "modern_sqlite"] }
|
||||||
bincode = "1.3.3"
|
bincode = "1.3.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -42,14 +42,12 @@ rand.workspace = true
|
||||||
reqwest = { version = "0.11", features = ["json"], optional = true }
|
reqwest = { version = "0.11", features = ["json"], optional = true }
|
||||||
scrypt = "0.7"
|
scrypt = "0.7"
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
# Remove fork dependency when a version with https://github.com/SeaQL/sea-orm/pull/1283 is released.
|
sea-orm = { version = "0.12.x", features = ["sqlx-postgres", "postgres-array", "runtime-tokio-rustls", "with-uuid"] }
|
||||||
sea-orm = { git = "https://github.com/zed-industries/sea-orm", rev = "18f4c691085712ad014a51792af75a9044bacee6", features = ["sqlx-postgres", "postgres-array", "runtime-tokio-rustls"] }
|
|
||||||
sea-query = "0.27"
|
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_derive.workspace = true
|
serde_derive.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
sha-1 = "0.9"
|
sha-1 = "0.9"
|
||||||
sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "postgres", "json", "time", "uuid", "any"] }
|
sqlx = { version = "0.7", features = ["runtime-tokio-rustls", "postgres", "json", "time", "uuid", "any"] }
|
||||||
time.workspace = true
|
time.workspace = true
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
tokio-tungstenite = "0.17"
|
tokio-tungstenite = "0.17"
|
||||||
|
@ -87,9 +85,9 @@ env_logger.workspace = true
|
||||||
indoc.workspace = true
|
indoc.workspace = true
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
lazy_static.workspace = true
|
lazy_static.workspace = true
|
||||||
sea-orm = { git = "https://github.com/zed-industries/sea-orm", rev = "18f4c691085712ad014a51792af75a9044bacee6", features = ["sqlx-sqlite"] }
|
sea-orm = { version = "0.12.x", features = ["sqlx-sqlite"] }
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
sqlx = { version = "0.6", features = ["sqlite"] }
|
sqlx = { version = "0.7", features = ["sqlite"] }
|
||||||
unindent.workspace = true
|
unindent.workspace = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
@ -19,11 +19,12 @@ use rpc::{
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
};
|
};
|
||||||
use sea_orm::{
|
use sea_orm::{
|
||||||
entity::prelude::*, ActiveValue, Condition, ConnectionTrait, DatabaseConnection,
|
entity::prelude::*,
|
||||||
DatabaseTransaction, DbErr, FromQueryResult, IntoActiveModel, IsolationLevel, JoinType,
|
sea_query::{Alias, Expr, OnConflict, Query},
|
||||||
QueryOrder, QuerySelect, Statement, TransactionTrait,
|
ActiveValue, Condition, ConnectionTrait, DatabaseConnection, DatabaseTransaction, DbErr,
|
||||||
|
FromQueryResult, IntoActiveModel, IsolationLevel, JoinType, QueryOrder, QuerySelect, Statement,
|
||||||
|
TransactionTrait,
|
||||||
};
|
};
|
||||||
use sea_query::{Alias, Expr, OnConflict, Query};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::{
|
use sqlx::{
|
||||||
migrate::{Migrate, Migration, MigrationSource},
|
migrate::{Migrate, Migration, MigrationSource},
|
||||||
|
@ -62,6 +63,7 @@ pub struct Database {
|
||||||
// separate files in the `queries` folder.
|
// separate files in the `queries` folder.
|
||||||
impl Database {
|
impl Database {
|
||||||
pub async fn new(options: ConnectOptions, executor: Executor) -> Result<Self> {
|
pub async fn new(options: ConnectOptions, executor: Executor) -> Result<Self> {
|
||||||
|
sqlx::any::install_default_drivers();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
options: options.clone(),
|
options: options.clone(),
|
||||||
pool: sea_orm::Database::connect(options).await?,
|
pool: sea_orm::Database::connect(options).await?,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
use sea_orm::DbErr;
|
use sea_orm::{entity::prelude::*, DbErr};
|
||||||
use sea_query::{Value, ValueTypeErr};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
macro_rules! id_type {
|
macro_rules! id_type {
|
||||||
|
@ -17,6 +16,7 @@ macro_rules! id_type {
|
||||||
Hash,
|
Hash,
|
||||||
Serialize,
|
Serialize,
|
||||||
Deserialize,
|
Deserialize,
|
||||||
|
DeriveValueType,
|
||||||
)]
|
)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct $name(pub i32);
|
pub struct $name(pub i32);
|
||||||
|
@ -42,40 +42,6 @@ macro_rules! id_type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<$name> for sea_query::Value {
|
|
||||||
fn from(value: $name) -> Self {
|
|
||||||
sea_query::Value::Int(Some(value.0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl sea_orm::TryGetable for $name {
|
|
||||||
fn try_get(
|
|
||||||
res: &sea_orm::QueryResult,
|
|
||||||
pre: &str,
|
|
||||||
col: &str,
|
|
||||||
) -> Result<Self, sea_orm::TryGetError> {
|
|
||||||
Ok(Self(i32::try_get(res, pre, col)?))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl sea_query::ValueType for $name {
|
|
||||||
fn try_from(v: Value) -> Result<Self, sea_query::ValueTypeErr> {
|
|
||||||
Ok(Self(value_to_integer(v)?))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn type_name() -> String {
|
|
||||||
stringify!($name).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn array_type() -> sea_query::ArrayType {
|
|
||||||
sea_query::ArrayType::Int
|
|
||||||
}
|
|
||||||
|
|
||||||
fn column_type() -> sea_query::ColumnType {
|
|
||||||
sea_query::ColumnType::Integer(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl sea_orm::TryFromU64 for $name {
|
impl sea_orm::TryFromU64 for $name {
|
||||||
fn try_from_u64(n: u64) -> Result<Self, DbErr> {
|
fn try_from_u64(n: u64) -> Result<Self, DbErr> {
|
||||||
Ok(Self(n.try_into().map_err(|_| {
|
Ok(Self(n.try_into().map_err(|_| {
|
||||||
|
@ -88,7 +54,7 @@ macro_rules! id_type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl sea_query::Nullable for $name {
|
impl sea_orm::sea_query::Nullable for $name {
|
||||||
fn null() -> Value {
|
fn null() -> Value {
|
||||||
Value::Int(None)
|
Value::Int(None)
|
||||||
}
|
}
|
||||||
|
@ -96,20 +62,6 @@ macro_rules! id_type {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn value_to_integer(v: Value) -> Result<i32, ValueTypeErr> {
|
|
||||||
match v {
|
|
||||||
Value::TinyInt(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
|
||||||
Value::SmallInt(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
|
||||||
Value::Int(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
|
||||||
Value::BigInt(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
|
||||||
Value::TinyUnsigned(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
|
||||||
Value::SmallUnsigned(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
|
||||||
Value::Unsigned(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
|
||||||
Value::BigUnsigned(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
|
||||||
_ => Err(ValueTypeErr),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
id_type!(BufferId);
|
id_type!(BufferId);
|
||||||
id_type!(AccessTokenId);
|
id_type!(AccessTokenId);
|
||||||
id_type!(ChannelChatParticipantId);
|
id_type!(ChannelChatParticipantId);
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
|
use super::*;
|
||||||
use rpc::proto::ChannelEdge;
|
use rpc::proto::ChannelEdge;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
type ChannelDescendants = HashMap<ChannelId, SmallSet<ChannelId>>;
|
type ChannelDescendants = HashMap<ChannelId, SmallSet<ChannelId>>;
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
|
@ -659,7 +658,7 @@ impl Database {
|
||||||
) -> Result<Vec<ChannelId>> {
|
) -> Result<Vec<ChannelId>> {
|
||||||
let paths = channel_path::Entity::find()
|
let paths = channel_path::Entity::find()
|
||||||
.filter(channel_path::Column::ChannelId.eq(channel_id))
|
.filter(channel_path::Column::ChannelId.eq(channel_id))
|
||||||
.order_by(channel_path::Column::IdPath, sea_query::Order::Desc)
|
.order_by(channel_path::Column::IdPath, sea_orm::Order::Desc)
|
||||||
.all(tx)
|
.all(tx)
|
||||||
.await?;
|
.await?;
|
||||||
let mut channel_ids = Vec::new();
|
let mut channel_ids = Vec::new();
|
||||||
|
|
|
@ -18,12 +18,12 @@ impl Database {
|
||||||
let user_b_participant = Alias::new("user_b_participant");
|
let user_b_participant = Alias::new("user_b_participant");
|
||||||
let mut db_contacts = contact::Entity::find()
|
let mut db_contacts = contact::Entity::find()
|
||||||
.column_as(
|
.column_as(
|
||||||
Expr::tbl(user_a_participant.clone(), room_participant::Column::Id)
|
Expr::col((user_a_participant.clone(), room_participant::Column::Id))
|
||||||
.is_not_null(),
|
.is_not_null(),
|
||||||
"user_a_busy",
|
"user_a_busy",
|
||||||
)
|
)
|
||||||
.column_as(
|
.column_as(
|
||||||
Expr::tbl(user_b_participant.clone(), room_participant::Column::Id)
|
Expr::col((user_b_participant.clone(), room_participant::Column::Id))
|
||||||
.is_not_null(),
|
.is_not_null(),
|
||||||
"user_b_busy",
|
"user_b_busy",
|
||||||
)
|
)
|
||||||
|
|
|
@ -184,7 +184,7 @@ impl Database {
|
||||||
Ok(user::Entity::find()
|
Ok(user::Entity::find()
|
||||||
.from_raw_sql(Statement::from_sql_and_values(
|
.from_raw_sql(Statement::from_sql_and_values(
|
||||||
self.pool.get_database_backend(),
|
self.pool.get_database_backend(),
|
||||||
query.into(),
|
query,
|
||||||
vec![like_string.into(), name_query.into(), limit.into()],
|
vec![like_string.into(), name_query.into(), limit.into()],
|
||||||
))
|
))
|
||||||
.all(&*tx)
|
.all(&*tx)
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl TestDb {
|
||||||
db.pool
|
db.pool
|
||||||
.execute(sea_orm::Statement::from_string(
|
.execute(sea_orm::Statement::from_string(
|
||||||
db.pool.get_database_backend(),
|
db.pool.get_database_backend(),
|
||||||
sql.into(),
|
sql,
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -134,7 +134,7 @@ impl Drop for TestDb {
|
||||||
db.pool
|
db.pool
|
||||||
.execute(sea_orm::Statement::from_string(
|
.execute(sea_orm::Statement::from_string(
|
||||||
db.pool.get_database_backend(),
|
db.pool.get_database_backend(),
|
||||||
query.into(),
|
query,
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
.log_err();
|
.log_err();
|
||||||
|
|
|
@ -26,7 +26,7 @@ postage.workspace = true
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
ordered-float.workspace = true
|
ordered-float.workspace = true
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
rusqlite = { version = "0.27.0", features = ["blob", "array", "modern_sqlite"] }
|
rusqlite.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
tree-sitter.workspace = true
|
tree-sitter.workspace = true
|
||||||
lazy_static.workspace = true
|
lazy_static.workspace = true
|
||||||
|
|
|
@ -7,7 +7,7 @@ publish = false
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
indoc.workspace = true
|
indoc.workspace = true
|
||||||
libsqlite3-sys = { version = "0.24", features = ["bundled"] }
|
libsqlite3-sys = { version = "0.26", features = ["bundled"] }
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
thread_local = "1.1.4"
|
thread_local = "1.1.4"
|
||||||
lazy_static.workspace = true
|
lazy_static.workspace = true
|
||||||
|
|
Loading…
Reference in a new issue