You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To use this type in the driver, create a matching struct and derive:
12
-
-`SerializeCql`: in order to be able to use this struct in query parameters. \
12
+
-`SerializeValue`: in order to be able to use this struct in query parameters. \
13
13
This macro requires fields of UDT and struct to have matching names, but the order
14
14
of the fields is not required to be the same. \
15
-
Note: you can use different name using `rename` attribute - see `SerializeCql` macro documentation.
15
+
Note: you can use different name using `rename` attribute - see `SerializeValue` macro documentation.
16
16
-`FromUserType`: in order to be able to use this struct in query results. \
17
17
This macro requires fields of UDT and struct to be in the same *ORDER*. \
18
-
This mismatch between `SerializeCql` and `FromUserType` requirements is a temporary situation - in the future `FromUserType` (or the macro that replaces it) will also require matching names.
18
+
This mismatch between `SerializeValue` and `FromUserType` requirements is a temporary situation - in the future `FromUserType` (or the macro that replaces it) will also require matching names.
Copy file name to clipboardexpand all lines: docs/source/migration-guides/0.11-serialization.md
+11-11
Original file line number
Diff line number
Diff line change
@@ -28,31 +28,31 @@ In version 0.11, a new set of traits is introduced and the old ones are deprecat
28
28
29
29
Both the old and the new APIs are based on three core traits:
30
30
31
-
-`Value` - called `SerializeCql` in the new API. A type that can serialize itself to a single CQL value. For example, `i32` serializes itself into a representation that is compatible with the CQL `int` type.
31
+
-`Value` - called `SerializeValue` in the new API. A type that can serialize itself to a single CQL value. For example, `i32` serializes itself into a representation that is compatible with the CQL `int` type.
32
32
-`ValueList` - called `SerializeRow` in the new API. A type that can serialize itself as a list of values for a CQL statement. For example, a `(i32, &str)` produces a list of two values which can be used in a query with two bind markers, e.g. `SELECT * FROM table WHERE pk = ? AND ck = ?`. Optionally, values in the produced list may be associated with names which is useful when using it with a query with named bind markers, e.g. `SELECT * FROM table WHERE pk = :pk AND ck = :ck`.
33
33
-`LegacyBatchValues`, previously named `BatchValues` - in new API replaced with new trait called (again) `BatchValues`. Represents a source of data for a batch request. It is essentially equivalent to a list of `ValueList`, one for each statement in the batch. For example, `((1, 2), (3, 4, 5))` can be used for a batch with two statements, the first one having two bind markers and the second one having three.
34
34
35
35
All methods which take one of the old traits were changed to take the new trait - notably, this includes `Session::query`, `(Caching)Session::execute`, `(Caching)Session::batch`.
36
36
37
-
The driver comes a set of `impl`s of those traits which allow to represent any CQL type (for example, see [Data Types](../data-types/data-types.md) page for a list of for which `Value` and `SerializeCql` is implemented). If the driver implements an old trait for some type, then it also provides implements the new trait for the same type.
37
+
The driver comes a set of `impl`s of those traits which allow to represent any CQL type (for example, see [Data Types](../data-types/data-types.md) page for a list of for which `Value` and `SerializeValue` is implemented). If the driver implements an old trait for some type, then it also provides implements the new trait for the same type.
38
38
39
39
## Migration scenarios
40
40
41
-
### Different default behavior in `SerializeRow`/`SerializeCql` macros
41
+
### Different default behavior in `SerializeRow`/`SerializeValue` macros
42
42
43
-
By default, the `SerializeRow` and `SerializeCql`**will match the fields in the Rust struct by name to bind marker names** (in case of `SerializeRow`) **or UDT field names** (in case of `SerializeCql`). This is different from the old `ValueList` and `IntoUserType` macros which did not look at the field names at all and would expect the user to order the fields correctly. While the new behavior is much more ergonomic, you might have reasons not to use it.
43
+
By default, the `SerializeRow` and `SerializeValue`**will match the fields in the Rust struct by name to bind marker names** (in case of `SerializeRow`) **or UDT field names** (in case of `SerializeValue`). This is different from the old `ValueList` and `IntoUserType` macros which did not look at the field names at all and would expect the user to order the fields correctly. While the new behavior is much more ergonomic, you might have reasons not to use it.
44
44
45
45
> **NOTE:** The deserialization macro counterparts `FromRow` and `FromUserType` have the same limitation as the old serialization macros - they require struct fields to be properly ordered. While a similar rework is planned for the deserialization traits in a future release, for the time being it might not be worth keeping the column names in sync with the database.
46
46
47
47
In order to bring the old behavior to the new macros (the only difference being type checking which cannot be disabled right now) you can configure it using attributes, as shown in the snippet below:
48
48
49
49
```rust
50
50
# externcrate scylla;
51
-
usescylla::SerializeCql;
51
+
usescylla::SerializeValue;
52
52
53
53
// The exact same attributes apply to the `SerializeRow` macro and their
Refer to the API reference page for the `SerializeRow` and `SerializeCql` macros in the `scylla` crate to learn more about the supported attributes and their meaning.
64
+
Refer to the API reference page for the `SerializeRow` and `SerializeValue` macros in the `scylla` crate to learn more about the supported attributes and their meaning.
65
65
66
66
### Preparing is mandatory with a non-empty list of values
67
67
@@ -80,13 +80,13 @@ In both cases, if the additional roundtrips are unacceptable, you should prepare
80
80
81
81
### Migrating from old to new traits *gradually*
82
82
83
-
In some cases, migration will be as easy as changing occurrences of `IntoUserType` to `SerializeCql` and `ValueList` to `SerializeRow` and adding some atributes for procedural macros. However, if you have a large enough codebase or some custom, complicated implementations of the old traits then you might not want to migrate everything at once. To support gradual migration, the old traits were not removed but rather deprecated, and we introduced some additional utilities.
83
+
In some cases, migration will be as easy as changing occurrences of `IntoUserType` to `SerializeValue` and `ValueList` to `SerializeRow` and adding some atributes for procedural macros. However, if you have a large enough codebase or some custom, complicated implementations of the old traits then you might not want to migrate everything at once. To support gradual migration, the old traits were not removed but rather deprecated, and we introduced some additional utilities.
84
84
85
85
#### Converting an object implementing an old trait to a new trait
86
86
87
87
We provide a number of newtype wrappers:
88
88
89
-
-`ValueAdapter` - implements `SerializeCql` if the type wrapped over implements `Value`,
89
+
-`ValueAdapter` - implements `SerializeValue` if the type wrapped over implements `Value`,
90
90
-`ValueListAdapter` - implements `SerializeRow` if the type wrapped over implements `ValueList`,
91
91
-`LegacyBatchValuesAdapter` - implements `BatchValues` if the type wrapped over implements `LegacyBatchValues`.
92
92
@@ -98,9 +98,9 @@ Conversion in the other direction is not possible.
98
98
99
99
#### Custom implementations of old traits
100
100
101
-
It is possible to directly generate an `impl` of `SerializeRow` and `SerializeCql` on a type which implements, respectively, `ValueList` or `Value`, without using the wrappers from the previous section. The following macros are provided:
101
+
It is possible to directly generate an `impl` of `SerializeRow` and `SerializeValue` on a type which implements, respectively, `ValueList` or `Value`, without using the wrappers from the previous section. The following macros are provided:
102
102
103
-
-`impl_serialize_cql_via_value` - implements `SerializeCql` if the type wrapped over implements `Value`,
103
+
-`impl_serialize_value_via_value` - implements `SerializeValue` if the type wrapped over implements `Value`,
104
104
-`impl_serialize_row_via_value_list` - implements `SerializeRow` if the type wrapped over implements `ValueList`,
105
105
106
106
The implementations are practically as those generated by the wrappers described in the previous section.
0 commit comments