-
Notifications
You must be signed in to change notification settings - Fork 20
Support serial data types. #135
Support serial data types. #135
Conversation
d2e2ef5
to
4b277b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for PR. I think instead of introducing new enum variants we can extend existing SmallInt
, Integer
and BigInt
. So you should have like:
SqlType::SmallInt(min),
SqlType::Integer(min),
SqlType::BigInt(min),
and also extend respective *TypeConstraint
and you need to update sql_engine
so that when user creates table with smallint
type then we create SqlType::SmallInt(u16::MIN_VALUE)
but if with smallserial
then SqlType::SmallInt(1)
.
it is actually what PostgreSQL
does.
postgres=# create table serials(col1 smallserial);
postgres=# \d serials
Table "public.serials"
Column | Type | Collation | Nullable | Default
--------+----------+-----------+----------+---------------------------------------
col1 | smallint | | not null | nextval('serials_col1_seq'::regclass)
Got it, thanks @alex-dukhno. |
@alex-dukhno let me know if I am on the right direction or not? |
d0eff35
to
40959d7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Only minor comments. To fix rustfmt
complaints you can run cargo +nightly fmt
src/sql_types/src/lib.rs
Outdated
Ok(_) => Ok(()), | ||
Err(e) if e.code == lexical::ErrorCode::InvalidDigit => Err(ConstraintError::NotAnInt), | ||
Err(_) => Err(ConstraintError::OutOfRange), | ||
if self.min < lexical::parse::<u16, _>(in_value).unwrap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please move if
check inside Ok(parsed)
branch, unwrap
ing will panic and in_value
will be parsed only once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, thanks.
src/sql_types/src/lib.rs
Outdated
Ok(_) => Ok(()), | ||
Err(e) if e.code == lexical::ErrorCode::InvalidDigit => Err(ConstraintError::NotAnInt), | ||
Err(_) => Err(ConstraintError::OutOfRange), | ||
if self.min < lexical::parse::<u32, _>(in_value).unwrap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
src/sql_types/src/lib.rs
Outdated
Err(e) if e.code == lexical::ErrorCode::InvalidDigit => Err(ConstraintError::NotAnInt), | ||
Err(_) => Err(ConstraintError::OutOfRange), | ||
if self.min < lexical::parse::<u64, _>(in_value).unwrap() { | ||
match lexical::parse::<u64, _>(in_value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
19aa9ed
to
49be91c
Compare
You can check |
@alex-dukhno In |
I am not sure about |
783e1b8
to
841ab2e
Compare
2e70ca0
to
1a24746
Compare
1a24746
to
c9fea1d
Compare
sqlparser::ast::DataType::Char(len) => SqlType::Char(len.unwrap_or(255)), | ||
sqlparser::ast::DataType::Varchar(len) => SqlType::VarChar(len.unwrap_or(255)), | ||
sqlparser::ast::DataType::Boolean => SqlType::Bool, | ||
sqlparser::ast::DataType::Custom(ObjectName(_serial)) => SqlType::Integer(1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sqlparser::ast::DataType::Custom(ObjectName(_serial)) => SqlType::Integer(1), | |
sqlparser::ast::DataType::Custom(name) => { | |
let name = name.to_string(); | |
if name == "smallserial" { | |
SqlType::SmallInt(1); | |
} else if name == "serial" { | |
SqlType::Integer(1); | |
} else if name == "bigserial" { | |
SqlType::BigInt(1); | |
} else { | |
unimplemented!("{:?} type is not supported", name) | |
} | |
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @alex-dukhno fixed, please review it.
d1927b6
to
0323093
Compare
I'll merge it as I am currently working on type improvements |
Thanks for the PR |
Closes #96
Please give your input @alex-dukhno!