Skip to content

Commit

Permalink
Remove QueryBuilder and MutationBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
photino committed Oct 19, 2023
1 parent 0afd69f commit a4393b9
Show file tree
Hide file tree
Showing 41 changed files with 108 additions and 458 deletions.
3 changes: 1 addition & 2 deletions examples/actix-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ publish = false
[dependencies]
actix-web = "4.4.0"
fluent = "0.16.0"
serde_json = "1.0.107"
tracing = "0.1.39"
tracing = "0.1.40"

[dependencies.serde]
version = "1.0.189"
Expand Down
1 change: 0 additions & 1 deletion examples/actix-app/src/controller/auth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use serde_json::json;
use zino::{prelude::*, Request, Response, Result};
use zino_model::user::{JwtAuthService, User};

Expand Down
3 changes: 1 addition & 2 deletions examples/actix-app/src/controller/stats.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use serde_json::json;
use zino::{prelude::*, Cluster, Request, Response, Result};

pub async fn index(req: Request) -> Result {
Expand All @@ -11,7 +10,7 @@ pub async fn index(req: Request) -> Result {
});
let data = json!({
"title": "Stats",
"output": serde_json::to_string_pretty(&stats).unwrap_or_default(),
"output": stats.to_string_pretty(),
});
Ok(res.render("output.html", data).into())
}
1 change: 0 additions & 1 deletion examples/actix-app/src/controller/user.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use fluent::fluent_args;
use serde_json::json;
use std::time::Instant;
use zino::{prelude::*, Request, Response, Result};
use zino_model::user::User;
Expand Down
3 changes: 0 additions & 3 deletions examples/actix-app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![feature(async_fn_in_trait)]
#![feature(lazy_cell)]

mod controller;
mod domain;
mod extension;
Expand Down
3 changes: 1 addition & 2 deletions examples/axum-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ publish = false
[dependencies]
axum = "0.6.20"
fluent = "0.16.0"
serde_json = "1.0.107"
tracing = "0.1.39"
tracing = "0.1.40"

[dependencies.serde]
version = "1.0.189"
Expand Down
1 change: 0 additions & 1 deletion examples/axum-app/src/controller/auth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use serde_json::json;
use zino::{prelude::*, Request, Response, Result};
use zino_model::user::{JwtAuthService, User};

Expand Down
3 changes: 1 addition & 2 deletions examples/axum-app/src/controller/stats.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use serde_json::json;
use zino::{prelude::*, Cluster, Request, Response, Result};

pub async fn index(req: Request) -> Result {
Expand All @@ -11,7 +10,7 @@ pub async fn index(req: Request) -> Result {
});
let data = json!({
"title": "Stats",
"output": serde_json::to_string_pretty(&stats).unwrap_or_default(),
"output": stats.to_string_pretty(),
});
Ok(res.render("output.html", data).into())
}
1 change: 0 additions & 1 deletion examples/axum-app/src/controller/user.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use fluent::fluent_args;
use serde_json::json;
use std::time::Instant;
use zino::{prelude::*, Request, Response, Result};
use zino_model::user::User;
Expand Down
3 changes: 0 additions & 3 deletions examples/axum-app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![feature(async_fn_in_trait)]
#![feature(lazy_cell)]

mod controller;
mod domain;
mod extension;
Expand Down
3 changes: 1 addition & 2 deletions examples/dioxus-desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ publish = false
[dependencies]
dioxus = "0.4.0"
dioxus-router = "0.4.1"
serde_json = "1.0.107"
tracing = "0.1.39"
tracing = "0.1.40"

[dependencies.dioxus-free-icons]
version = "0.7.0"
Expand Down
Binary file added examples/dioxus-desktop/public/icons/64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion examples/dioxus-desktop/src/service/stargazer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::App;
use serde_json::json;
use zino::prelude::*;

pub async fn list_stargazers(per_page: u8, page: usize) -> Result<Vec<Map>, Error> {
Expand Down
6 changes: 3 additions & 3 deletions zino-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ sha2 = "0.10.8"
sysinfo = "0.29.10"
task-local-extensions = "0.1.4"
toml = "0.8.2"
tracing = "0.1.39"
tracing = "0.1.40"
tracing-appender = "0.2.2"
url = "2.4.1"

Expand Down Expand Up @@ -204,7 +204,7 @@ version = "0.12.0"
optional = true

[dependencies.minijinja]
version = "1.0.8"
version = "1.0.9"
optional = true
features = ["debug", "loader"]

Expand Down Expand Up @@ -294,7 +294,7 @@ features = [
]

[dependencies.uuid]
version = "1.4.1"
version = "1.5.0"
features = [
"fast-rng",
"serde",
Expand Down
14 changes: 14 additions & 0 deletions zino-core/src/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
//! Authentication and authorization.
//!
//! ## Feature flags
//!
//! The following optional features are available:
//!
//! | Name | Description | Default? |
//! |---------------|------------------------------------------------------|----------|
//! | `auth-oauth2` | Enables the integration with [`oauth2`]. | No |
//! | `auth-oidc` | Enables the integration with [`openidconnect`]. | No |
//! | `auth-totp` | Enables the integration with [`totp-rs`]. | No |
//!
//! [`oauth2`]: https://crates.io/crates/oauth2
//! [`openidconnect`]: https://crates.io/crates/openidconnect
//! [`totp-rs`]: https://crates.io/crates/totp-rs

mod access_key;
mod authentication;
Expand Down
8 changes: 8 additions & 0 deletions zino-core/src/extension/json_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ pub trait JsonValueExt {
/// If the vec is empty, it also returns `None`.
fn parse_str_array(&self) -> Option<Vec<&str>>;

/// Returns a pretty-printed String of JSON.
fn to_string_pretty(&self) -> String;

/// Attempts to convert the JSON value to the CSV bytes.
fn to_csv(&self, buffer: Vec<u8>) -> Result<Vec<u8>, csv::Error>;

Expand Down Expand Up @@ -255,6 +258,11 @@ impl JsonValueExt for JsonValue {
(!vec.is_empty()).then_some(vec)
}

#[inline]
fn to_string_pretty(&self) -> String {
format!("{self:#}")
}

fn to_csv(&self, buffer: Vec<u8>) -> Result<Vec<u8>, csv::Error> {
match &self {
JsonValue::Array(vec) => {
Expand Down
8 changes: 8 additions & 0 deletions zino-core/src/format/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
//! Wrappers for manipulating common file formats.
//!
//! ## Feature flags
//!
//! The following optional features are available:
//!
//! | Name | Description | Default? |
//! |---------------|------------------------------------------------------|----------|
//! | `format-pdf` | Enables the support for `PDF` documents. | No |

#[cfg(feature = "format-pdf")]
mod pdf_document;
Expand Down
32 changes: 30 additions & 2 deletions zino-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,34 @@
//!
//! Core types and traits for [`zino`].
//!
//! ## Feature flags
//!
//! The following optional features are available:
//!
//! | Name | Description | Default? |
//! |---------------------|--------------------------------------------------------|----------|
//! | `accessor` | Enables the data access layer built with [`opendal`]. | No |
//! | `cache` | Enables the cache services. | No |
//! | `chatbot` | Enables the chatbot services. | No |
//! | `connector` | Enables the data source connectors. | No |
//! | `crypto-sm` | Enables China's Standards of Encryption Algorithms. | No |
//! | `format` | Enables the support for common file formats. | No |
//! | `orm` | Enables the ORM for MySQL, PostgreSQL or **SQLite**. | No |
//! | `runtime-async-std` | Enables the [`async-std`] runtime. | No |
//! | `runtime-tokio` | Enables the [`tokio`] runtime. | Yes |
//! | `tls-native` | Enables the [`native-tls`] TLS backend. | No |
//! | `tls-rustls` | Enables the [`rustls`] TLS backend. | Yes |
//! | `view` | Enables the HTML template rendering. | No |
//!
//! [`zino`]: https://github.com/photino/zino
//! [`opendal`]: https://crates.io/crates/opendal
//! [`async-std`]: https://crates.io/crates/async-std
//! [`tokio`]: https://crates.io/crates/tokio
//! [`native-tls`]: https://crates.io/crates/native-tls
//! [`rustls`]: https://crates.io/crates/rustls

#![allow(async_fn_in_trait)]
#![allow(stable_features)]
#![doc(html_favicon_url = "https://photino.github.io/zino-docs-zh/assets/zino-logo.png")]
#![doc(html_logo_url = "https://photino.github.io/zino-docs-zh/assets/zino-logo.svg")]
#![feature(associated_type_defaults)]
Expand All @@ -35,10 +60,10 @@ pub mod cache;
pub mod chatbot;
#[cfg(feature = "connector")]
pub mod connector;
#[cfg(feature = "orm")]
pub mod database;
#[cfg(feature = "format")]
pub mod format;
#[cfg(feature = "orm")]
pub mod orm;
#[cfg(feature = "view")]
pub mod view;

Expand All @@ -57,6 +82,9 @@ pub mod schedule;
pub mod state;
pub mod trace;

#[doc(no_inline)]
pub use serde_json::json;

/// A JSON value.
pub type JsonValue = serde_json::Value;

Expand Down
4 changes: 2 additions & 2 deletions zino-core/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub use apache_avro::schema;
pub use column::{Column, EncodeColumn};
pub use context::QueryContext;
pub use hook::ModelHooks;
pub use mutation::{Mutation, MutationBuilder};
pub use query::{Query, QueryBuilder};
pub use mutation::Mutation;
pub use query::Query;
pub use reference::Reference;
pub use row::DecodeRow;
pub use translation::Translation;
Expand Down
62 changes: 0 additions & 62 deletions zino-core/src/model/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,65 +92,3 @@ impl Mutation {
&self.updates
}
}

/// A builder type for model mutations.
#[derive(Debug, Default)]
pub struct MutationBuilder {
// Editable fields.
fields: Vec<String>,
// Updates.
updates: Map,
}

impl MutationBuilder {
/// Creates a new instance.
#[inline]
pub fn new() -> Self {
Self {
fields: Vec::new(),
updates: Map::new(),
}
}

/// Sets the value of the field.
#[inline]
pub fn set<S, T>(mut self, field: S, value: T) -> Self
where
S: Into<String>,
T: Into<JsonValue>,
{
self.updates.upsert(field, value);
self
}

/// Increments the field by a specified value
#[inline]
pub fn inc<S, T>(mut self, field: S, value: T) -> Self
where
S: Into<String>,
T: Into<JsonValue>,
{
self.updates.upsert(field, Map::from_entry("$inc", value));
self
}

/// Multiplies the value of a field by a number.
#[inline]
pub fn mul<S, T>(mut self, field: S, value: T) -> Self
where
S: Into<String>,
T: Into<JsonValue>,
{
self.updates.upsert(field, Map::from_entry("$mul", value));
self
}

/// Constructs an instance of `Mutation`.
#[inline]
pub fn build(self) -> Mutation {
Mutation {
fields: self.fields,
updates: self.updates,
}
}
}
Loading

0 comments on commit a4393b9

Please sign in to comment.