Skip to content

Commit

Permalink
support unsigned int type
Browse files Browse the repository at this point in the history
  • Loading branch information
garrensmith committed Dec 1, 2021
1 parent 39f5d8c commit 68d22eb
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ opt-level = 3
codegen-units = 1
opt-level = 'z' # Optimize for size.
#strip="symbols"

[patch."https://github.com/prisma/quaint"]
quaint = {git = 'https://github.com/serejkaaa512/quaint/', branch = 'feature/unsigned_int' }
1 change: 1 addition & 0 deletions libs/datamodel/core/src/json/dmmf/to_dmmf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ fn prisma_value_to_serde(value: &PrismaValue) -> serde_json::Value {
}
PrismaValue::Int(val) => serde_json::Value::Number(serde_json::Number::from_f64(*val as f64).unwrap()),
PrismaValue::BigInt(val) => serde_json::Value::String(val.to_string()),
PrismaValue::UnsignedInt(val) => serde_json::Value::String(val.to_string()),
PrismaValue::DateTime(val) => serde_json::Value::String(val.to_rfc3339()),
PrismaValue::Null => serde_json::Value::Null,
PrismaValue::Uuid(val) => serde_json::Value::String(val.to_string()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ impl<'a> LowerDmlToAst<'a> {
PrismaValue::Float(value) => ast::Expression::NumericValue(value.to_string(), ast::Span::empty()),
PrismaValue::Int(value) => ast::Expression::NumericValue(value.to_string(), ast::Span::empty()),
PrismaValue::BigInt(value) => ast::Expression::NumericValue(value.to_string(), ast::Span::empty()),
PrismaValue::UnsignedInt(value) => ast::Expression::NumericValue(value.to_string(), ast::Span::empty()),
PrismaValue::Null => ast::Expression::ConstantValue("null".to_string(), ast::Span::empty()),
PrismaValue::Uuid(val) => Self::lower_string(val),
PrismaValue::Json(val) => Self::lower_string(val),
Expand Down
3 changes: 3 additions & 0 deletions libs/prisma-value/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub enum PrismaValue {
#[serde(serialize_with = "serialize_bigint")]
BigInt(i64),

UnsignedInt(u64),

#[serde(serialize_with = "serialize_bytes")]
Bytes(Vec<u8>),
}
Expand Down Expand Up @@ -243,6 +245,7 @@ impl fmt::Display for PrismaValue {
PrismaValue::Json(x) => x.fmt(f),
PrismaValue::Xml(x) => x.fmt(f),
PrismaValue::BigInt(x) => x.fmt(f),
PrismaValue::UnsignedInt(x) => x.fmt(f),
PrismaValue::List(x) => {
let as_string = format!("{:?}", x);
as_string.fmt(f)
Expand Down
2 changes: 2 additions & 0 deletions libs/prisma-value/src/sql_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ impl<'a> TryFrom<Value<'a>> for PrismaValue {
let val = match pv {
Value::Integer(i) => i.map(PrismaValue::Int).unwrap_or(PrismaValue::Null),

Value::UnsignedInteger(u) => u.map(PrismaValue::UnsignedInt).unwrap_or(PrismaValue::Null),

Value::Float(Some(f)) => match f {
f if f.is_nan() => {
return Err(crate::ConversionFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ impl ScalarFieldExt for ScalarField {
(PrismaValue::Enum(e), _) => e.into(),
(PrismaValue::Int(i), _) => (i as i64).into(),
(PrismaValue::BigInt(i), _) => (i as i64).into(),
(PrismaValue::UnsignedInt(u), _) => (u as u64).into(),
(PrismaValue::Uuid(u), _) => u.to_string().into(),
(PrismaValue::List(l), _) => Value::Array(Some(l.into_iter().map(|x| self.value(x)).collect())),
(PrismaValue::Json(s), _) => Value::Json(Some(serde_json::from_str::<serde_json::Value>(&s).unwrap())),
Expand Down Expand Up @@ -52,6 +53,7 @@ pub fn convert_lossy<'a>(pv: PrismaValue) -> Value<'a> {
PrismaValue::Enum(e) => e.into(),
PrismaValue::Int(i) => (i as i64).into(),
PrismaValue::BigInt(i) => (i as i64).into(),
PrismaValue::UnsignedInt(u) => (u as u64).into(),
PrismaValue::Uuid(u) => u.to_string().into(),
PrismaValue::List(l) => Value::Array(Some(l.into_iter().map(convert_lossy).collect())),
PrismaValue::Json(s) => Value::Json(serde_json::from_str(&s).unwrap()),
Expand Down
4 changes: 4 additions & 0 deletions query-engine/core/src/query_document/query_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::hash::Hash;
#[derive(Debug, Clone, Eq)]
pub enum QueryValue {
Int(i64),
UnsignedInt(u64),
Float(BigDecimal),
String(String),
Boolean(bool),
Expand All @@ -19,6 +20,7 @@ impl PartialEq for QueryValue {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(QueryValue::Int(n1), QueryValue::Int(n2)) => n1 == n2,
(QueryValue::UnsignedInt(n1), QueryValue::UnsignedInt(n2)) => n1 == n2,
(QueryValue::Float(n1), QueryValue::Float(n2)) => n1 == n2,
(QueryValue::String(s1), QueryValue::String(s2)) => s1 == s2,
(QueryValue::Boolean(b1), QueryValue::Boolean(b2)) => b1 == b2,
Expand All @@ -35,6 +37,7 @@ impl Hash for QueryValue {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
match self {
Self::Int(i) => i.hash(state),
Self::UnsignedInt(u) => u.hash(state),
Self::Float(f) => f.hash(state),
Self::String(s) => s.hash(state),
Self::Boolean(b) => b.hash(state),
Expand Down Expand Up @@ -74,6 +77,7 @@ impl From<PrismaValue> for QueryValue {
PrismaValue::Xml(s) => Self::String(s),
PrismaValue::Bytes(b) => Self::String(prisma_value::encode_bytes(&b)),
PrismaValue::BigInt(i) => Self::Int(i),
PrismaValue::UnsignedInt(u) => Self::UnsignedInt(u),
}
}
}

0 comments on commit 68d22eb

Please sign in to comment.