Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for BYTEA Postgres primary keys #286

Closed
robot-head opened this issue Nov 2, 2021 · 8 comments · Fixed by #287
Closed

Support for BYTEA Postgres primary keys #286

robot-head opened this issue Nov 2, 2021 · 8 comments · Fixed by #287
Assignees

Comments

@robot-head
Copy link

Currently any column marked as a primary key needs to satisfy TryFromU64.

A BYTEA (Vec<u8>) does not satisfy this (and, I don't think ever could).

Would it be possible to add support for this type of primary key? We use it a lot in our application

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 2, 2021

TryFromU64 can definitely return Err in that case. That's how UUID primary key is supported.
We can do something to support Vec<u8> in our test suite, but it should be working already.

pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub uuid: Uuid,
#[sea_orm(column_name = "type", enum_name = "Type")]
pub ty: String,
pub key: String,
pub value: String,
pub bytes: Vec<u8>,
pub date: Option<Date>,
pub time: Option<Time>,
}

@robot-head
Copy link
Author

robot-head commented Nov 2, 2021

Seeing this
image

With this example model:

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "foobar")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub primary_a: Vec<u8>,
    #[sea_orm(primary_key, auto_increment = false)]
    pub primary_b: Vec<u8>,
}

@billy1624
Copy link
Member

The errors are expected. I will create a PR now to make it work! Stay tuned

@robot-head
Copy link
Author

Thank you so much!

Loving this crate so far btw, refactoring our large codebase to make it finally unit testable.

Thanks for the quick help

@billy1624
Copy link
Member

Thanks for the support! Do recommend sea-orm to your friends loll :P

@billy1624
Copy link
Member

Hey @robot-head, please try #287.

Simply...

sea-orm = { version = "^0.3", git = "https://github.com/SeaQL/sea-orm.git", branch = "vec-u8-primary-key", ... }

P.S. For now, it works on Postgres but not MySQL and MariaDB

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 2, 2021

Loving this crate so far btw, refactoring our large codebase to make it finally unit testable

Cool, we definitely would like to know a bit more about your scenario!

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 2, 2021

0.3.2

arpancodes pushed a commit to arpancodes/sea-orm that referenced this issue Apr 8, 2022
…p_with_time_zone_len

issues-285 Fix timestamp_with_time_zone_len
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants