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

feat(cube): support postgres cube #3188

Merged
merged 52 commits into from
Jul 12, 2024
Merged

Conversation

jayy-lmao
Copy link
Contributor

I work on a sqlx codegen tool, and had an issue posted about the lack of support for the 'cube' extension type (https://www.postgresql.org/docs/current/cube.html).

jayy-lmao/sql-gen#9

I could not see any outstanding issues / PRs involving Cube, so can create an issue first if necessary for discussion.
Not particularly attached to how to structure the struct, serialisation, or deserialisation - ultimately just want to be able to support it for my sql-gen tool so that @yellowHatpro can carry on with using it for their project.

@jayy-lmao
Copy link
Contributor Author

jayy-lmao commented Apr 9, 2024

Sorry for the build jobs -- running locally the encoding seems to be fine.
Haven't been able to replicate locally with amd64 platform, alpine etc. Still figuring out why the encoding is different.

Update: have been able to reproduce by using

    let row = s.try_next().await?.unwrap();
    let rec = row.try_get::<PgCube, _>(0)?;

Locally to test. Will continue to investigate.

README.md Outdated Show resolved Hide resolved
@jayy-lmao
Copy link
Contributor Author

Have handled the text case, tests now passing ☺️

sqlx-postgres/src/type_checking.rs Outdated Show resolved Hide resolved
sqlx-postgres/src/types/cube.rs Outdated Show resolved Hide resolved
sqlx-postgres/src/types/cube.rs Outdated Show resolved Hide resolved
sqlx-postgres/src/types/cube.rs Outdated Show resolved Hide resolved
@jayy-lmao
Copy link
Contributor Author

Have made the changes to vector indexing :)

}
}

impl TryFrom<&str> for PgCube {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a FromStr impl.

It's fine to have both, but it's surprising to have a TryFrom<&str> impl and not a FromStr impl.

The only reason to do that is if Self wants to borrow from the string (think zero-copy parsing) which the FromStr trait doesn't support due to its lack of a lifetime bound.

@jayy-lmao
Copy link
Contributor Author

jayy-lmao commented Apr 24, 2024

Have made changes

  • trimming the input string to make it more flexible for the spec & for user input
  • allow for _cube array type (And included a test for it)
  • remove TryFrom behaviour for &[u8], using direct function instead
  • avoid double creating a buffer, but just writing directly to the PgArgumentBuffer

@jayy-lmao
Copy link
Contributor Author

Apologies, I've been away for a little - I've addressed all comments but if there's any other changes that are wanted let me know

Copy link
Collaborator

@abonander abonander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jayy-lmao one last thing, since #3126 was merged, you'll need to rebase and fix the compilation errors.

@abonander
Copy link
Collaborator

Note that I only today realized that main has been broken for the past few weeks and I'm still working on fixing Clippy warnings (turned into errors by CI) from that.

Don't worry about fixing errors in code you didn't touch.

@jayy-lmao
Copy link
Contributor Author

jayy-lmao commented Jun 6, 2024

Note that I only today realized that main has been broken for the past few weeks and I'm still working on fixing Clippy warnings (turned into errors by CI) from that.

Don't worry about fixing errors in code you didn't touch.

Just saw this then.

Oh well, at least I've resolved the changes in Encode implementation.
Glad it supports returning errors now ☺️

Let me know if I can be any help with the errors.

@jayy-lmao
Copy link
Contributor Author

@abonander have rebased onto main now that builds are passing, and updated to address new linting rules 👍

@jayy-lmao jayy-lmao requested a review from abonander July 10, 2024 06:22
@abonander abonander merged commit 0db12a9 into launchbadge:main Jul 12, 2024
64 checks passed
jrasanen pushed a commit to jrasanen/sqlx that referenced this pull request Oct 14, 2024
* feat: add cube

* docs: cube docs

* docs: update readme

* fix: cube is now not feature flagged

* fix: formatting

* fix: typeo for PgCube vs Cube

* fix: correct types

* fix: postgres only types for cube

* fix: cube readme

* fix: dont unwrap cubes

* fix: typo on interval

* fix: zero volume cube array

* fix: return type

* fix: update tests

* fix: run with one test type

* fix: log bytes in error

* fix: typo in test

* fix: log bytes for failed length

* fix: string deser

* docs: remove cube from readme

* fix: int to float

* fix: trim floats

* fix: exttra test

* fix: type safe into vectors

* fix: improve error messages

* docs: remove comments

* fix: front load most important logic and const at start

* fix: extract constants

* fix: flags

* fix: avoid redundant buffer creation and use FromStr trait

* fix: handle serializing

* test: cube vec test

* fix: no array cube test

* fix: update test with array for cube

* fix: dont use try from for u8

* fix: conditionally remove padding

* fix: conditional trimming

* fix: idiomatic trimming

* fix: linting

* fix: remove whitespace

* fix: lower case array

* fix: spacing input

* test: one more vec test

* fix: trim square brackets in case they are using postgres spec page

* fix: result types

* fix: format

* fix: box error

* fix: the borrow produces a value

* fix: self serialise

* chore: merge main

* fix: borrow

* fix: clippy

---------

Co-authored-by: James Holman <[email protected]>
jrasanen pushed a commit to jrasanen/sqlx that referenced this pull request Oct 14, 2024
* feat: add cube

* docs: cube docs

* docs: update readme

* fix: cube is now not feature flagged

* fix: formatting

* fix: typeo for PgCube vs Cube

* fix: correct types

* fix: postgres only types for cube

* fix: cube readme

* fix: dont unwrap cubes

* fix: typo on interval

* fix: zero volume cube array

* fix: return type

* fix: update tests

* fix: run with one test type

* fix: log bytes in error

* fix: typo in test

* fix: log bytes for failed length

* fix: string deser

* docs: remove cube from readme

* fix: int to float

* fix: trim floats

* fix: exttra test

* fix: type safe into vectors

* fix: improve error messages

* docs: remove comments

* fix: front load most important logic and const at start

* fix: extract constants

* fix: flags

* fix: avoid redundant buffer creation and use FromStr trait

* fix: handle serializing

* test: cube vec test

* fix: no array cube test

* fix: update test with array for cube

* fix: dont use try from for u8

* fix: conditionally remove padding

* fix: conditional trimming

* fix: idiomatic trimming

* fix: linting

* fix: remove whitespace

* fix: lower case array

* fix: spacing input

* test: one more vec test

* fix: trim square brackets in case they are using postgres spec page

* fix: result types

* fix: format

* fix: box error

* fix: the borrow produces a value

* fix: self serialise

* chore: merge main

* fix: borrow

* fix: clippy

---------

Co-authored-by: James Holman <[email protected]>
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 this pull request may close these issues.

2 participants