Skip to content

Commit 4f9babb

Browse files
authored
Upgrade to scylla 0.10 (#39)
1 parent cbacc3a commit 4f9babb

File tree

17 files changed

+251
-106
lines changed

17 files changed

+251
-106
lines changed

.github/workflows/scylla.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ jobs:
2424
- ${{ github.workspace }}:/workspace
2525
steps:
2626
- uses: actions/checkout@v2
27-
- name: Install stable 1.66
27+
- name: Install stable 1.73
2828
uses: actions-rs/toolchain@v1
2929
with:
30-
toolchain: 1.72.0
30+
toolchain: 1.73.0
3131
default: true
3232
components: rustfmt, clippy
3333
- name: Load .env file

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target/
2-
.idea
2+
.idea
3+
.DS_Store

.run/Test all.run.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
<option name="withSudo" value="false" />
1010
<option name="buildTarget" value="REMOTE" />
1111
<option name="backtrace" value="SHORT" />
12-
<envs />
12+
<envs>
13+
<env name="TRYBUILD" value="overwrite" />
14+
</envs>
1315
<option name="isRedirectInput" value="false" />
1416
<option name="redirectInputPath" value="" />
1517
<method v="2">

Cargo.lock

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resolver = "2"
1010

1111
[workspace.package]
1212
edition = "2021"
13-
version = "0.1.17"
13+
version = "0.1.18"
1414
authors = ["Jasper Visser <[email protected]>"]
1515
repository = "https://github.com/Jasperav/catalytic"
1616
readme = "../README.md"
@@ -19,7 +19,7 @@ categories = ["database"]
1919
license = "MIT"
2020

2121
[workspace.dependencies]
22-
scylla = "0.9.0" # This crate is specifically build for this version
22+
scylla = "0.10.0" # This crate is specifically build for this version
2323
once_cell = "1.18"
2424
heck = "0.4"
2525
tokio = { version = "1", features = ["time", "rt-multi-thread", "io-util"] }

catalytic_query_parser/src/extract_query_metadata.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,11 @@ pub fn extract_query_meta_data(query: impl AsRef<str>) -> QueryMetadata {
4444
column_type: ColumnType::Int,
4545
value: ParameterizedValue::Limit,
4646
});
47-
} else {
48-
match ttl {
49-
Some(ttl) if ttl == Ttl::Parameterized => {
50-
parameterized_columns_types.push(ParameterizedColumnType {
51-
column_type: ColumnType::Int,
52-
value: ParameterizedValue::UsingTtl,
53-
});
54-
}
55-
_ => {} // Do nothing
56-
}
47+
} else if let Some(Ttl::Parameterized) = ttl {
48+
parameterized_columns_types.push(ParameterizedColumnType {
49+
column_type: ColumnType::Int,
50+
value: ParameterizedValue::UsingTtl,
51+
});
5752
}
5853

5954
// ColumnInTable can be reused in ranges, so filter duplicates
@@ -123,7 +118,7 @@ pub fn replace_select_wildcard(query: &str, columns: &[ColumnInTable]) -> String
123118
pub fn test_query(query: impl AsRef<str>) -> QueryMetadata {
124119
let query = query.as_ref();
125120
let qmd = extract_query_meta_data(query);
126-
let mut values = SerializedValues::with_capacity(qmd.parameterized_columns_types.len());
121+
let mut values = SerializedValues::new();
127122

128123
for parameterized_column_type in &qmd.parameterized_columns_types {
129124
add_random_value(&mut values, parameterized_column_type);

catalytic_query_parser/src/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ impl Parse for Query {
183183
.iter()
184184
.filter(|r| r.parameterized)
185185
.collect::<Vec<_>>();
186-
let ident_count = idents.len();
187186
let types_comparison = idents
188187
.iter()
189188
.enumerate()
@@ -205,7 +204,13 @@ impl Parse for Query {
205204
.collect::<Vec<syn::Type>>();
206205

207206
let serialized_values = quote! {{
208-
let mut serialized_values = catalytic::scylla::frame::value::SerializedValues::with_capacity(#ident_count);
207+
let mut size = 0;
208+
209+
#(
210+
size += std::mem::size_of_val(#idents);
211+
)*
212+
213+
let mut serialized_values = catalytic::scylla::frame::value::SerializedValues::with_capacity(size);
209214

210215
#(
211216
// Check if the type is correct

catalytic_table_to_struct/example/src/generated/another_test_table.rs

+30-7
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,12 @@ pub async fn truncate(session: &CachingSession) -> ScyllaQueryResult {
171171
impl<'a> AnotherTestTableRef<'a> {
172172
#[doc = r" Returns a struct that can perform an insert operation"]
173173
pub fn insert_qv(&self) -> Result<Insert, SerializeValuesError> {
174-
let mut serialized = SerializedValues::with_capacity(4usize);
174+
let mut size = 0;
175+
size += std::mem::size_of_val(self.a);
176+
size += std::mem::size_of_val(self.b);
177+
size += std::mem::size_of_val(self.c);
178+
size += std::mem::size_of_val(self.d);
179+
let mut serialized = SerializedValues::with_capacity(size);
175180
serialized.add_value(&self.a)?;
176181
serialized.add_value(&self.b)?;
177182
serialized.add_value(&self.c)?;
@@ -188,7 +193,13 @@ impl<'a> AnotherTestTableRef<'a> {
188193
}
189194
#[doc = r" Returns a struct that can perform an insert operation with a TTL"]
190195
pub fn insert_ttl_qv(&self, ttl: TtlType) -> Result<Insert, SerializeValuesError> {
191-
let mut serialized = SerializedValues::with_capacity(5usize);
196+
let mut size = 0;
197+
size += std::mem::size_of_val(self.a);
198+
size += std::mem::size_of_val(self.b);
199+
size += std::mem::size_of_val(self.c);
200+
size += std::mem::size_of_val(self.d);
201+
size += std::mem::size_of_val(&ttl);
202+
let mut serialized = SerializedValues::with_capacity(size);
192203
serialized.add_value(&self.a)?;
193204
serialized.add_value(&self.b)?;
194205
serialized.add_value(&self.c)?;
@@ -281,7 +292,11 @@ impl From<PrimaryKeyRef<'_>> for PrimaryKey {
281292
impl PrimaryKeyRef<'_> {
282293
#[doc = r" Returns a struct that can perform a unique row selection"]
283294
pub fn select_unique_qv(&self) -> Result<SelectUnique<AnotherTestTable>, SerializeValuesError> {
284-
let mut serialized_values = SerializedValues::with_capacity(3usize);
295+
let mut size = 0;
296+
size += std::mem::size_of_val(self.a);
297+
size += std::mem::size_of_val(self.b);
298+
size += std::mem::size_of_val(self.c);
299+
let mut serialized_values = SerializedValues::with_capacity(size);
285300
serialized_values.add_value(&self.a)?;
286301
serialized_values.add_value(&self.b)?;
287302
serialized_values.add_value(&self.c)?;
@@ -308,7 +323,11 @@ impl PrimaryKeyRef<'_> {
308323
pub fn select_unique_expect_qv(
309324
&self,
310325
) -> Result<SelectUniqueExpect<AnotherTestTable>, SerializeValuesError> {
311-
let mut serialized_values = SerializedValues::with_capacity(3usize);
326+
let mut size = 0;
327+
size += std::mem::size_of_val(self.a);
328+
size += std::mem::size_of_val(self.b);
329+
size += std::mem::size_of_val(self.c);
330+
let mut serialized_values = SerializedValues::with_capacity(size);
312331
serialized_values.add_value(&self.a)?;
313332
serialized_values.add_value(&self.b)?;
314333
serialized_values.add_value(&self.c)?;
@@ -333,7 +352,7 @@ impl PrimaryKeyRef<'_> {
333352
impl PrimaryKeyRef<'_> {
334353
#[doc = "Returns a struct that can perform an update operation for column d"]
335354
pub fn update_d_qv(&self, val: &i32) -> Result<Update, SerializeValuesError> {
336-
let mut serialized_values = SerializedValues::with_capacity(4usize);
355+
let mut serialized_values = SerializedValues::with_capacity(std::mem::size_of_val(val));
337356
serialized_values.add_value(&val)?;
338357
serialized_values.add_value(&self.a)?;
339358
serialized_values.add_value(&self.b)?;
@@ -383,7 +402,7 @@ impl PrimaryKeyRef<'_> {
383402
panic!("Empty update array")
384403
}
385404
let mut query = vec![];
386-
let mut serialized_values = SerializedValues::with_capacity(val.len() + 3usize);
405+
let mut serialized_values = SerializedValues::new();
387406
for v in val {
388407
match v {
389408
UpdatableColumnRef::D(v) => {
@@ -423,7 +442,11 @@ impl PrimaryKeyRef<'_> {
423442
impl PrimaryKeyRef<'_> {
424443
#[doc = r" Returns a struct that can perform a single row deletion"]
425444
pub fn delete_qv(&self) -> Result<DeleteUnique, SerializeValuesError> {
426-
let mut serialized_values = SerializedValues::with_capacity(3usize);
445+
let mut size = 0;
446+
size += std::mem::size_of_val(self.a);
447+
size += std::mem::size_of_val(self.b);
448+
size += std::mem::size_of_val(self.c);
449+
let mut serialized_values = SerializedValues::with_capacity(size);
427450
serialized_values.add_value(&self.a)?;
428451
serialized_values.add_value(&self.b)?;
429452
serialized_values.add_value(&self.c)?;

catalytic_table_to_struct/example/src/generated/child.rs

+26-9
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,12 @@ pub async fn truncate(session: &CachingSession) -> ScyllaQueryResult {
171171
impl<'a> ChildRef<'a> {
172172
#[doc = r" Returns a struct that can perform an insert operation"]
173173
pub fn insert_qv(&self) -> Result<Insert, SerializeValuesError> {
174-
let mut serialized = SerializedValues::with_capacity(4usize);
174+
let mut size = 0;
175+
size += std::mem::size_of_val(self.birthday);
176+
size += std::mem::size_of_val(self.enum_json);
177+
size += std::mem::size_of_val(self.json);
178+
size += std::mem::size_of_val(self.json_nullable);
179+
let mut serialized = SerializedValues::with_capacity(size);
175180
serialized.add_value(&self.birthday)?;
176181
serialized.add_value(&self.enum_json)?;
177182
serialized.add_value(&self.json)?;
@@ -188,7 +193,13 @@ impl<'a> ChildRef<'a> {
188193
}
189194
#[doc = r" Returns a struct that can perform an insert operation with a TTL"]
190195
pub fn insert_ttl_qv(&self, ttl: TtlType) -> Result<Insert, SerializeValuesError> {
191-
let mut serialized = SerializedValues::with_capacity(5usize);
196+
let mut size = 0;
197+
size += std::mem::size_of_val(self.birthday);
198+
size += std::mem::size_of_val(self.enum_json);
199+
size += std::mem::size_of_val(self.json);
200+
size += std::mem::size_of_val(self.json_nullable);
201+
size += std::mem::size_of_val(&ttl);
202+
let mut serialized = SerializedValues::with_capacity(size);
192203
serialized.add_value(&self.birthday)?;
193204
serialized.add_value(&self.enum_json)?;
194205
serialized.add_value(&self.json)?;
@@ -277,7 +288,9 @@ impl From<PrimaryKeyRef<'_>> for PrimaryKey {
277288
impl PrimaryKeyRef<'_> {
278289
#[doc = r" Returns a struct that can perform a unique row selection"]
279290
pub fn select_unique_qv(&self) -> Result<SelectUnique<Child>, SerializeValuesError> {
280-
let mut serialized_values = SerializedValues::with_capacity(1usize);
291+
let mut size = 0;
292+
size += std::mem::size_of_val(self.birthday);
293+
let mut serialized_values = SerializedValues::with_capacity(size);
281294
serialized_values.add_value(&self.birthday)?;
282295
Ok(SelectUnique::new(Qv {
283296
query: SELECT_UNIQUE_QUERY,
@@ -302,7 +315,9 @@ impl PrimaryKeyRef<'_> {
302315
pub fn select_unique_expect_qv(
303316
&self,
304317
) -> Result<SelectUniqueExpect<Child>, SerializeValuesError> {
305-
let mut serialized_values = SerializedValues::with_capacity(1usize);
318+
let mut size = 0;
319+
size += std::mem::size_of_val(self.birthday);
320+
let mut serialized_values = SerializedValues::with_capacity(size);
306321
serialized_values.add_value(&self.birthday)?;
307322
Ok(SelectUniqueExpect::new(Qv {
308323
query: SELECT_UNIQUE_QUERY,
@@ -328,7 +343,7 @@ impl PrimaryKeyRef<'_> {
328343
&self,
329344
val: &crate::MyJsonEnum,
330345
) -> Result<Update, SerializeValuesError> {
331-
let mut serialized_values = SerializedValues::with_capacity(2usize);
346+
let mut serialized_values = SerializedValues::with_capacity(std::mem::size_of_val(val));
332347
serialized_values.add_value(&val)?;
333348
serialized_values.add_value(&self.birthday)?;
334349
Ok(Update::new(Qv {
@@ -354,7 +369,7 @@ impl PrimaryKeyRef<'_> {
354369
impl PrimaryKeyRef<'_> {
355370
#[doc = "Returns a struct that can perform an update operation for column json"]
356371
pub fn update_json_qv(&self, val: &crate::MyJsonType) -> Result<Update, SerializeValuesError> {
357-
let mut serialized_values = SerializedValues::with_capacity(2usize);
372+
let mut serialized_values = SerializedValues::with_capacity(std::mem::size_of_val(val));
358373
serialized_values.add_value(&val)?;
359374
serialized_values.add_value(&self.birthday)?;
360375
Ok(Update::new(Qv {
@@ -383,7 +398,7 @@ impl PrimaryKeyRef<'_> {
383398
&self,
384399
val: &std::option::Option<crate::MyJsonType>,
385400
) -> Result<Update, SerializeValuesError> {
386-
let mut serialized_values = SerializedValues::with_capacity(2usize);
401+
let mut serialized_values = SerializedValues::with_capacity(std::mem::size_of_val(val));
387402
serialized_values.add_value(&val)?;
388403
serialized_values.add_value(&self.birthday)?;
389404
Ok(Update::new(Qv {
@@ -437,7 +452,7 @@ impl PrimaryKeyRef<'_> {
437452
panic!("Empty update array")
438453
}
439454
let mut query = vec![];
440-
let mut serialized_values = SerializedValues::with_capacity(val.len() + 1usize);
455+
let mut serialized_values = SerializedValues::new();
441456
for v in val {
442457
match v {
443458
UpdatableColumnRef::EnumJson(v) => {
@@ -483,7 +498,9 @@ impl PrimaryKeyRef<'_> {
483498
impl PrimaryKeyRef<'_> {
484499
#[doc = r" Returns a struct that can perform a single row deletion"]
485500
pub fn delete_qv(&self) -> Result<DeleteUnique, SerializeValuesError> {
486-
let mut serialized_values = SerializedValues::with_capacity(1usize);
501+
let mut size = 0;
502+
size += std::mem::size_of_val(self.birthday);
503+
let mut serialized_values = SerializedValues::with_capacity(size);
487504
serialized_values.add_value(&self.birthday)?;
488505
Ok(DeleteUnique::new(Qv {
489506
query: DELETE_QUERY,

0 commit comments

Comments
 (0)