Skip to content

feat: add support to more postgres types issue#102#105

Merged
debba merged 19 commits intoTabularisDB:mainfrom
dev-void-7:feat/support-more-pg-types
Mar 28, 2026
Merged

feat: add support to more postgres types issue#102#105
debba merged 19 commits intoTabularisDB:mainfrom
dev-void-7:feat/support-more-pg-types

Conversation

@dev-void-7
Copy link
Copy Markdown
Contributor

@dev-void-7 dev-void-7 commented Mar 25, 2026

Supported Postgres Types

  • Simple types
  • Domain types
  • Simple Composite types
  • Array of Simple types
  • Nested composite types
  • Array of composite type
  • Nested arrays
  • Ranges
  • Enums

Limitation With sqlx

I think it is not possible to implement Nested composite types, Array of composite type or Nested arrays because sqlx does not expose (does not make the public outside of the crate) important functions and methods to do that

Suggested Solution

Replace sqlx with tokio-postgres or the sync version postgres because they expose most of the functions needed to implement the features mentioned above.

what do you think?

Comment thread src-tauri/src/drivers/postgres/extract.rs Outdated
Comment thread src-tauri/src/drivers/postgres/extract.rs Outdated
@kilo-code-bot
Copy link
Copy Markdown

kilo-code-bot bot commented Mar 25, 2026

Code Review Summary

Status: 4 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 2
WARNING 0
SUGGESTION 2
Issue Details (click to expand)

CRITICAL

File Line Issue
extract/array.rs 34 Incorrect buffer length check - check buf.len() * dimentions < 8 * dimentions is algebraically equivalent to buf.len() < 8 but should ensure buf.len() >= 12 + 8 * dimensions
extract/common.rs 11 Missing bounds check before buf[..4] - will panic if buffer has fewer than 4 bytes

SUGGESTION

File Line Issue
extract/array.rs 17 Typo: dimentions should be dimensions (also appears on lines 20, 26, 31, 34, 61, 87)
extract/composite.rs 9 Typo: recieved should be received
Notes on Previous Review

The previous review comments regarding DateTime<Local> and i8 array handling (on the deleted extract.rs file) are now obsolete. The file has been replaced with a new module structure using tokio-postgres. The new implementation:

  • Uses a different architecture with separate modules for simple, array, and composite types
  • No longer handles DateTime<Local> (only DateTime<Utc> for TIMESTAMPTZ)
  • Handles nested arrays and composite types through recursive extraction
Files Reviewed (6 files)
  • src-tauri/src/drivers/postgres/extract/array.rs - New array extraction logic with buffer parsing bugs
  • src-tauri/src/drivers/postgres/extract/common.rs - Missing bounds check on buffer operations
  • src-tauri/src/drivers/postgres/extract/composite.rs - Typo in error message
  • src-tauri/src/drivers/postgres/extract/mod.rs - Main extraction module implementing FromSql
  • src-tauri/src/drivers/postgres/extract/simple.rs - Simple type extraction (no issues found)
  • src-tauri/src/drivers/postgres/mod.rs - Updated driver using tokio-postgres (no issues found)
  • src-tauri/src/pool_manager.rs - Updated pool manager with deadpool-postgres (no issues found)

Reviewed by kimi-k2.5-0127 · 555,131 tokens

@dev-void-7 dev-void-7 changed the title feat: add support to more postgres types #102 feat: add support to more postgres types issue#102 Mar 25, 2026
@debba
Copy link
Copy Markdown
Collaborator

debba commented Mar 25, 2026

Yes looks ok to me , you can go ahead

@debba
Copy link
Copy Markdown
Collaborator

debba commented Mar 26, 2026

@dev-void-7 I will wait you complete tasks related for doing a review, let me know when is ready thanks

@dev-void-7
Copy link
Copy Markdown
Contributor Author

Hi,
It will take some time because sqlx (postgres related logic) is used in more than one place.
I'll let you know as soon as I'm finished.

My regards

let dimentions = dimentions as usize;

// each dimension must have at least 8 bytes info
if buf.len() * dimentions < 8 * dimentions {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CRITICAL: Incorrect buffer length check logic

The check buf.len() * dimentions < 8 * dimentions is algebraically equivalent to buf.len() < 8 (assuming dimensions > 0), which is incorrect.

At this point, buf still contains the 12-byte header. The check should ensure there are 8 * dimensions bytes remaining AFTER the header for dimension descriptors.

Suggested change
if buf.len() * dimentions < 8 * dimentions {
if buf.len() < 12 + 8 * dimentions {

}

pub fn split_at_value_len<'a>(buf: &mut &'a [u8]) -> Result<&'a [u8], ()> {
let len = i32::from_be_bytes(match buf[..4].try_into() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CRITICAL: Missing bounds check before slicing

This will panic if buf has fewer than 4 bytes. Should check buf.len() < 4 first.

Suggested change
let len = i32::from_be_bytes(match buf[..4].try_into() {
if buf.len() < 4 {
log::error!("Buffer too short: {}", buf.len());
return Err(());
}
let len = i32::from_be_bytes(match buf[..4].try_into() {
Ok(bytes) => bytes,
Err(e) => {
log::error!("Failed to parse value length: {:?}", e);
return Err(());
}
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no need to check because try_into will not panic, but will return Result instead,, in addition to the fact that Result is checked.

return Err(());
};

let dimentions = i32::from_be_bytes(buf[..4].try_into().unwrap());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Typo in variable name

dimentions should be dimensions. This typo appears throughout the file (lines 17, 20, 26, 31, 34, 61, 87).

Suggested change
let dimentions = i32::from_be_bytes(buf[..4].try_into().unwrap());
let dimensions = i32::from_be_bytes(buf[..4].try_into().unwrap());

#[inline]
pub fn extract_or_null(fields: &Vec<Field>, buf: &mut &[u8]) -> Result<JsonValue, ()> {
if buf.len() == 0 {
log::error!("recieved empty buffer");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Typo in error message

recieved should be received.

Suggested change
log::error!("recieved empty buffer");
log::error!("received empty buffer");

@dev-void-7
Copy link
Copy Markdown
Contributor Author

dev-void-7 commented Mar 27, 2026

@debba hi,
i made some tests to the software on my laptop and it can be said that there are no problems now with Nested Arrays, Composite types and Composite[] 🎉.
i have some notes:

  • rustfmt breaked some lines into multiple lines (i don't know why. i use the default configuration) and tried to fix that but couldn't.
  • i modified two macro_rules so that they align with tokio-postgres too.
  • i made some unit tests for Array type extraction only.

inform me if there is any problem in the code.
Thank You very much in advance for your hard work and for this very amazing project.

My Regards

@debba
Copy link
Copy Markdown
Collaborator

debba commented Mar 28, 2026

Hi @dev-void-7 ,
thanks a lot for your work.

I tried to do some tests with array columns but always have: Error: db error

immagine

@dev-void-7
Copy link
Copy Markdown
Contributor Author

@debba
i will check that as soon as possible.
I think this is related to the change from sqlx to tokio_postgres.

@dev-void-7
Copy link
Copy Markdown
Contributor Author

dev-void-7 commented Mar 28, 2026

@debba
hi,

there is a syntax error with the query
INSERT test_null_arr (arr_col) VALUES (ARRAY[]::INT[], ARRAY[1]::INT[])
the correct query is:
INSERT test_null_arr (arr_col) VALUES (ARRAY[]::INT[]), (ARRAY[1]::INT[])

anyway this is related to the error message being unclear at all.

i tried to fix this like that:
image

what do you think?

@debba
Copy link
Copy Markdown
Collaborator

debba commented Mar 28, 2026

Yes looks great, it could be wonderful to have the message and a button for viewing full details what do you think?

@dev-void-7
Copy link
Copy Markdown
Contributor Author

dev-void-7 commented Mar 28, 2026

i think to implement this we should return a struct instead of String for error messages with two fields summary and details. if the use wants the details he/she can click a button to display them otherwise a summary will be shown.

anyway if we want to do that i think it should be in a separate PR. do you agree?

i am going to push the commits i made so you can test things 😊. Thank you in advance

@debba debba merged commit 13c733b into TabularisDB:main Mar 28, 2026
@debba
Copy link
Copy Markdown
Collaborator

debba commented Mar 28, 2026

Thanks, I will merge it :)

@dev-void-7
Copy link
Copy Markdown
Contributor Author

Thank You very much this was my first PR 😊🎉🔥. I hope my contribution was helpful

There is still some types that is not supported like enums and ranges. once i finish them i will open another PR

My Regards

@debba
Copy link
Copy Markdown
Collaborator

debba commented Mar 28, 2026

The thanks go entirely to you; I’ll create a release between today and tomorrow.
I hope you’ll continue collaborating, t’s really helpful to have talented people like you.
If you’d like, share the project; the more it grows, the more we’ll be able to solve a lot of things in a short time.

@dev-void-7
Copy link
Copy Markdown
Contributor Author

For sure i will continue collaborating specifically on Postgres part

have a nice day 🔥.

@debba
Copy link
Copy Markdown
Collaborator

debba commented Mar 29, 2026

I added my thanks here:

https://tabularis.dev/blog/v0912-tokio-postgres-minimax-json-editor

@dev-void-7 dev-void-7 deleted the feat/support-more-pg-types branch March 29, 2026 11:10
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