@@ -40,7 +40,7 @@ impl ScyllaSession {
40
40
Either3 :: B ( query) => self . session . query ( query. query . clone ( ) , values) . await ,
41
41
Either3 :: C ( prepared) => self . session . execute ( & prepared. prepared , values) . await ,
42
42
}
43
- . map_err ( |_ | {
43
+ . map_err ( |e | {
44
44
let query = match query {
45
45
Either3 :: A ( query) => query,
46
46
Either3 :: B ( query) => query. query . contents . clone ( ) ,
@@ -49,7 +49,7 @@ impl ScyllaSession {
49
49
50
50
napi:: Error :: new (
51
51
napi:: Status :: InvalidArg ,
52
- format ! ( "Something went wrong with your query. - [{query}] - {parameters:?}" ) ,
52
+ format ! ( "Something went wrong with your query. - [{query}] - {parameters:?}\n {e} " ) ,
53
53
)
54
54
} ) ?;
55
55
@@ -71,10 +71,10 @@ impl ScyllaSession {
71
71
. session
72
72
. query ( scylla_query. query . clone ( ) , values)
73
73
. await
74
- . map_err ( |_ | {
74
+ . map_err ( |e | {
75
75
napi:: Error :: new (
76
76
napi:: Status :: InvalidArg ,
77
- format ! ( "Something went wrong with your query. - [{scylla_query}] - {parameters:?}" ) ,
77
+ format ! ( "Something went wrong with your query. - [{scylla_query}] - {parameters:?}\n {e} " ) ,
78
78
)
79
79
} ) ?;
80
80
@@ -83,16 +83,51 @@ impl ScyllaSession {
83
83
84
84
#[ napi]
85
85
pub async fn prepare ( & self , query : String ) -> napi:: Result < PreparedStatement > {
86
- let prepared = self . session . prepare ( query. clone ( ) ) . await . map_err ( |_ | {
86
+ let prepared = self . session . prepare ( query. clone ( ) ) . await . map_err ( |e | {
87
87
napi:: Error :: new (
88
88
napi:: Status :: InvalidArg ,
89
- format ! ( "Something went wrong with your prepared statement. - [{query}]" ) ,
89
+ format ! ( "Something went wrong with your prepared statement. - [{query}]\n {e} " ) ,
90
90
)
91
91
} ) ?;
92
92
93
93
Ok ( PreparedStatement :: new ( prepared) )
94
94
}
95
95
96
+ /// Perform a batch query\
97
+ /// Batch contains many `simple` or `prepared` queries which are executed at once\
98
+ /// Batch doesn't return any rows
99
+ ///
100
+ /// Batch values must contain values for each of the queries
101
+ ///
102
+ /// See [the book](https://rust-driver.docs.scylladb.com/stable/queries/batch.html) for more information
103
+ ///
104
+ /// # Arguments
105
+ /// * `batch` - Batch to be performed
106
+ /// * `values` - List of values for each query, it's the easiest to use an array of arrays
107
+ ///
108
+ /// # Example
109
+ /// ```javascript
110
+ /// const nodes = process.env.CLUSTER_NODES?.split(",") ?? ["127.0.0.1:9042"];
111
+ ///
112
+ /// const cluster = new Cluster({ nodes });
113
+ /// const session = await cluster.connect();
114
+ ///
115
+ /// const batch = new BatchStatement();
116
+ ///
117
+ /// await session.execute("CREATE KEYSPACE IF NOT EXISTS batch_statements WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }");
118
+ /// await session.useKeyspace("batch_statements");
119
+ /// await session.execute("CREATE TABLE IF NOT EXISTS users (id UUID PRIMARY KEY, name TEXT)");
120
+ ///
121
+ /// const simpleStatement = new Query("INSERT INTO users (id, name) VALUES (?, ?)");
122
+ /// const preparedStatement = await session.prepare("INSERT INTO users (id, name) VALUES (?, ?)");
123
+ ///
124
+ /// batch.appendStatement(simpleStatement);
125
+ /// batch.appendStatement(preparedStatement);
126
+ ///
127
+ /// await session.batch(batch, [[Uuid.randomV4(), "Alice"], [Uuid.randomV4(), "Bob"]]);
128
+ ///
129
+ /// console.log(await session.execute("SELECT * FROM users"));
130
+ /// ```
96
131
#[ napi]
97
132
#[ allow( clippy:: type_complexity) ]
98
133
pub async fn batch (
@@ -159,7 +194,7 @@ impl ScyllaSession {
159
194
///
160
195
/// const result = await session
161
196
/// .execute("SELECT * FROM scylla_tables limit ?", [1])
162
- /// .catch((err) => console.error(err) );
197
+ /// .catch(console.error);
163
198
/// ```
164
199
#[ napi]
165
200
pub async fn use_keyspace (
0 commit comments