-
Notifications
You must be signed in to change notification settings - Fork 19
feat(rust): add support to u64 and u256 #100
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -909,6 +909,57 @@ impl Buffer { | |
self.output.push(b'i'); | ||
Ok(self) | ||
} | ||
/// Record an integer value for the given column. | ||
/// | ||
/// ``` | ||
/// # use questdb::Result; | ||
/// # use questdb::ingress::Buffer; | ||
/// # fn main() -> Result<()> { | ||
/// # let mut buffer = Buffer::new(); | ||
/// # buffer.table("x")?; | ||
/// buffer.column_u64("col_name", 42)?; | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
/// | ||
/// or | ||
/// | ||
/// ``` | ||
/// # use questdb::Result; | ||
/// # use questdb::ingress::Buffer; | ||
/// use questdb::ingress::ColumnName; | ||
/// | ||
/// # fn main() -> Result<()> { | ||
/// # let mut buffer = Buffer::new(); | ||
/// # buffer.table("x")?; | ||
/// let col_name = ColumnName::new("col_name")?; | ||
/// buffer.column_u64(col_name, 42); | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
pub fn column_u64<'a, N>(&mut self, name: N, value: u64) -> Result<&mut Self> | ||
where | ||
N: TryInto<ColumnName<'a>>, | ||
Error: From<N::Error>, | ||
{ | ||
self.write_column_key(name)?; | ||
let mut buf = itoa::Buffer::new(); | ||
let printed = buf.format(value); | ||
self.output.extend_from_slice(printed.as_bytes()); | ||
self.output.push(b'i'); | ||
Ok(self) | ||
} | ||
Comment on lines
+940
to
+951
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be misleading for the API to accept a datatype that the server does not. |
||
|
||
pub fn column_long256<'a, N>(&mut self, name: N, value: [u8; 32]) -> Result<&mut Self> | ||
where | ||
N: TryInto<ColumnName<'a>>, | ||
Error: From<N::Error>, | ||
{ | ||
self.write_column_key(name)?; | ||
let ser = format!("0x{}i", hex::encode(value)); | ||
self.output.extend_from_slice(ser.as_bytes()); | ||
Ok(self) | ||
} | ||
Comment on lines
+953
to
+962
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good start! This is indeed a missing feature and a very welcome contribution. The long256 encoding looks correct. For us to consider the PR, it should include tests and a C and C++ API and tests against a live DB ( As per this function itself, it would need minor tweaking to avoid allocating memory. Given that the number is a fixed-size slice, you should be able to just call API docs should include any byte-order considerations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just remembered.. might want to reserve the exact additional needed bytes here too. |
||
|
||
/// Record a floating point value for the given column. | ||
/// | ||
|
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.
Don't need the external dep.
Explained faster alternative later.