-
Notifications
You must be signed in to change notification settings - Fork 123
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
Is it possible to use the new SerializeRow
without using a generic type?
#890
Comments
I suppose the closest thing would be |
@piodul can multiple values serialize itself to a single SerializeRow? Then maybe it could work. But using a Box requires heap allocations… I don’t need type safety since Catalytic auto generates structs from the databas so it looks like a waste to me |
Yes.
Creating a
Type checking happens in In any case, you need to pass the type of the value during serialization, and this requirement won't go away in the future. I suppose if you wanted to rewrite your code in the most straightforward way, you could do it like this: pub fn insert_qv(&self) -> Result<Insert, SerializeValuesError> {
let mut serialized = SerializedValues::new();
serialized.add_value(&self.name, &ColumnType::Text)?; // <- note that you need to pass the type
serialized.add_value(&self.age, &ColumnType::Int)?;
serialized.add_value(&self.email, &ColumnType::Text)?;
serialized.add_value(&self.row_type, &ColumnType::Text)?;
Ok(Insert::new(Qv {
query: INSERT_QUERY,
values: serialized,
}))
} Then, the last problem to be solved would be to pass I'm not sure, however, how we would go about passing fn serialized(&self, ctx: &RowSerializationContext<'_>) -> SerializedResult<'_>; ... but that's adding a trait method just to make a single optimization possible. Maybe it's not too bad, but if other solutions are possible then I'd rather avoid complicating the traits' interface. |
Adding an escape like you mention for |
No, there isn't at the moment.
Probably, yes. It should be possible to add the changes I described in a backwards-compatible way, so perhaps we will release |
Ok thanks for the quick reply, I will keep an eye out for the 0.11.1 release |
This is only one additional heap allocation - driver already does several of them for each request + actually sending and receiving data trough network. Worrying about this may potentially be a premature optimization.
I'd be a bit reluctant to add such a wrapper to our driver:
Imho implementing such a struct in user code is a good enough bar for disabling type checks - if someone really wants it, it's not a problem, but it will force developer to think twice before doing it. I'd recommend you to go with |
@Lorak-mmk I am trying to convert the code to scylla 1.11.0 but I am still struggling at dynamically serialize rows and then execute it some time later. I need this for multiple places, e.g. dynamic queries. The
I have a query and I want to execute it with a random value based on the column type. How can I do this? Using a Box is ok, but how would I go from It seems like the derive macro It seems I have to introduce a separate struct for serializing values. If I can get some help converting It now seems like the |
Sorry for taking so long to respond.
It sounds to me like it would be a good solution to your problems, what do you think? |
I am trying to convert Catalytic to the new API's but I am stuck while transforming these structs: https://github.com/Jasperav/Catalytic/blob/6b74c52a4926d5aee7034a2b545befcbb61b08b2/catalytic/src/query_transform.rs#L202:
Example impl here https://github.com/Jasperav/Catalytic/blob/6b74c52a4926d5aee7034a2b545befcbb61b08b2/catalytic_table_to_struct/example/src/generated/person.rs#L170:
So previously I could use a non-generic type as placeholder for the
Qv
struct in which users could safely execute predefined queries with values. Now, I don't see an impl forSerializeRow
with a concrete-non-generic struct (expect for the Legacy one) which I can use.Is there any 'unsafe' not-generic struct which impls
SerializeRow
which I can use as a typeholder forQv
? It was really easy passing around theQv
struct in my applications and just execute whenever I want without using any generic types. Looks like the only way now is working with the Legacy struct but maybe there is a better way. I don't feel like it's a good idea to make separate structs for every single query so you get 1Qv
for each method.The text was updated successfully, but these errors were encountered: