Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 39a4cdf

Browse files
committed
Deprecate batch_execute
It's being replaced by the more capable `simple_query` API.
1 parent aeaea5e commit 39a4cdf

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

postgres/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,8 @@ impl Connection {
13041304
pub fn set_transaction_config(&self, config: &transaction::Config) -> Result<()> {
13051305
let mut command = "SET SESSION CHARACTERISTICS AS TRANSACTION".to_owned();
13061306
config.build_command(&mut command);
1307-
self.batch_execute(&command)
1307+
self.simple_query(&command)
1308+
.map(|_| ())
13081309
}
13091310

13101311
/// Execute a sequence of SQL statements.
@@ -1341,6 +1342,7 @@ impl Connection {
13411342
/// CREATE INDEX ON purchase (time);
13421343
/// ").unwrap();
13431344
/// ```
1345+
#[deprecated(since="0.15.3", note="please use `simple_query` instead")]
13441346
pub fn batch_execute(&self, query: &str) -> Result<()> {
13451347
self.0.borrow_mut().quick_query(query).map(|_| ())
13461348
}
@@ -1449,6 +1451,7 @@ pub trait GenericConnection {
14491451
fn transaction<'a>(&'a self) -> Result<Transaction<'a>>;
14501452

14511453
/// Like `Connection::batch_execute`.
1454+
#[deprecated(since="0.15.3", note="please use `simple_query` instead")]
14521455
fn batch_execute(&self, query: &str) -> Result<()>;
14531456

14541457
/// Like `Connection::is_active`.
@@ -1480,7 +1483,8 @@ impl GenericConnection for Connection {
14801483
}
14811484

14821485
fn batch_execute(&self, query: &str) -> Result<()> {
1483-
self.batch_execute(&query)
1486+
self.simple_query(query)
1487+
.map(|_| ())
14841488
}
14851489

14861490
fn is_active(&self) -> bool {
@@ -1514,7 +1518,8 @@ impl<'a> GenericConnection for Transaction<'a> {
15141518
}
15151519

15161520
fn batch_execute(&self, query: &str) -> Result<()> {
1517-
self.batch_execute(&query)
1521+
self.simple_query(query)
1522+
.map(|_| ())
15181523
}
15191524

15201525
fn simple_query(&self, query: &str) -> Result<Vec<TextRows>> {

postgres/src/transaction.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@ impl<'conn> Transaction<'conn> {
226226
}
227227

228228
/// Like `Connection::batch_execute`.
229+
#[deprecated(since="0.15.3", note="please use `simple_query` instead")]
229230
pub fn batch_execute(&self, query: &str) -> Result<()> {
230-
self.conn.batch_execute(query)
231+
self.simple_query(query)
232+
.map(|_| ())
231233
}
232234

233235
/// Like `Connection::simple_query`.
@@ -283,7 +285,8 @@ impl<'conn> Transaction<'conn> {
283285
pub fn set_config(&self, config: &Config) -> Result<()> {
284286
let mut command = "SET TRANSACTION".to_owned();
285287
config.build_command(&mut command);
286-
self.batch_execute(&command).map(|_| ())
288+
self.simple_query(&command)
289+
.map(|_| ())
287290
}
288291

289292
/// Determines if the transaction is currently set to commit or roll back.

postgres/tests/test.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ fn test_stmt_finish() {
396396
}
397397

398398
#[test]
399+
#[allow(deprecated)]
399400
fn test_batch_execute() {
400401
let conn = or_panic!(Connection::connect(
401402
"postgres://postgres@localhost:5433",
@@ -415,6 +416,7 @@ fn test_batch_execute() {
415416
}
416417

417418
#[test]
419+
#[allow(deprecated)]
418420
fn test_batch_execute_error() {
419421
let conn = or_panic!(Connection::connect(
420422
"postgres://postgres@localhost:5433",
@@ -435,6 +437,7 @@ fn test_batch_execute_error() {
435437
}
436438

437439
#[test]
440+
#[allow(deprecated)]
438441
fn test_transaction_batch_execute() {
439442
let conn = or_panic!(Connection::connect(
440443
"postgres://postgres@localhost:5433",
@@ -1091,6 +1094,7 @@ fn test_execute_copy_from_err() {
10911094
}
10921095

10931096
#[test]
1097+
#[allow(deprecated)]
10941098
fn test_batch_execute_copy_from_err() {
10951099
let conn = or_panic!(Connection::connect(
10961100
"postgres://postgres@localhost:5433",
@@ -1156,7 +1160,7 @@ fn test_query_copy_out_err() {
11561160
"postgres://postgres@localhost:5433",
11571161
TlsMode::None,
11581162
));
1159-
or_panic!(conn.batch_execute(
1163+
or_panic!(conn.simple_query(
11601164
"
11611165
CREATE TEMPORARY TABLE foo (id INT);
11621166
INSERT INTO foo (id) VALUES (0), (1), (2), (3)",
@@ -1175,7 +1179,7 @@ fn test_copy_out() {
11751179
"postgres://postgres@localhost:5433",
11761180
TlsMode::None,
11771181
));
1178-
or_panic!(conn.batch_execute(
1182+
or_panic!(conn.simple_query(
11791183
"
11801184
CREATE TEMPORARY TABLE foo (id INT);
11811185
INSERT INTO foo (id) VALUES (0), (1), (2), (3)",
@@ -1185,7 +1189,7 @@ fn test_copy_out() {
11851189
let count = or_panic!(stmt.copy_out(&[], &mut buf));
11861190
assert_eq!(count, 4);
11871191
assert_eq!(buf, b"0\n1\n2\n3\n");
1188-
or_panic!(conn.batch_execute("SELECT 1"));
1192+
or_panic!(conn.simple_query("SELECT 1"));
11891193
}
11901194

11911195
#[test]
@@ -1194,7 +1198,7 @@ fn test_copy_out_error() {
11941198
"postgres://postgres@localhost:5433",
11951199
TlsMode::None,
11961200
));
1197-
or_panic!(conn.batch_execute(
1201+
or_panic!(conn.simple_query(
11981202
"
11991203
CREATE TEMPORARY TABLE foo (id INT);
12001204
INSERT INTO foo (id) VALUES (0), (1), (2), (3)",
@@ -1380,7 +1384,7 @@ fn test_transaction_isolation_level() {
13801384
#[test]
13811385
fn test_rows_index() {
13821386
let conn = Connection::connect("postgres://postgres@localhost:5433", TlsMode::None).unwrap();
1383-
conn.batch_execute(
1387+
conn.simple_query(
13841388
"
13851389
CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY);
13861390
INSERT INTO foo (id) VALUES (1), (2), (3);
@@ -1413,7 +1417,7 @@ fn test_type_names() {
14131417
#[test]
14141418
fn test_conn_query() {
14151419
let conn = Connection::connect("postgres://postgres@localhost:5433", TlsMode::None).unwrap();
1416-
conn.batch_execute(
1420+
conn.simple_query(
14171421
"
14181422
CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY);
14191423
INSERT INTO foo (id) VALUES (1), (2), (3);
@@ -1492,7 +1496,7 @@ fn explicit_types() {
14921496
#[test]
14931497
fn simple_query() {
14941498
let conn = Connection::connect("postgres://postgres@localhost:5433", TlsMode::None).unwrap();
1495-
conn.batch_execute(
1499+
conn.simple_query(
14961500
"
14971501
CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY);
14981502
INSERT INTO foo (id) VALUES (1), (2), (3);

postgres/tests/types/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ fn test_pg_database_datname() {
362362
#[test]
363363
fn test_slice() {
364364
let conn = Connection::connect("postgres://postgres@localhost:5433", TlsMode::None).unwrap();
365-
conn.batch_execute(
365+
conn.simple_query(
366366
"CREATE TEMPORARY TABLE foo (id SERIAL PRIMARY KEY, f VARCHAR);
367367
INSERT INTO foo (f) VALUES ('a'), ('b'), ('c'), ('d');",
368368
).unwrap();
@@ -382,7 +382,7 @@ fn test_slice() {
382382
#[test]
383383
fn test_slice_wrong_type() {
384384
let conn = Connection::connect("postgres://postgres@localhost:5433", TlsMode::None).unwrap();
385-
conn.batch_execute("CREATE TEMPORARY TABLE foo (id SERIAL PRIMARY KEY)")
385+
conn.simple_query("CREATE TEMPORARY TABLE foo (id SERIAL PRIMARY KEY)")
386386
.unwrap();
387387

388388
let stmt = conn.prepare("SELECT * FROM foo WHERE id = ANY($1)")
@@ -449,7 +449,7 @@ fn domain() {
449449
}
450450

451451
let conn = Connection::connect("postgres://postgres@localhost:5433", TlsMode::None).unwrap();
452-
conn.batch_execute(
452+
conn.simple_query(
453453
"CREATE DOMAIN pg_temp.session_id AS bytea CHECK(octet_length(VALUE) = 16);
454454
CREATE TABLE pg_temp.foo (id pg_temp.session_id);",
455455
).unwrap();
@@ -464,7 +464,7 @@ fn domain() {
464464
#[test]
465465
fn composite() {
466466
let conn = Connection::connect("postgres://postgres@localhost:5433", TlsMode::None).unwrap();
467-
conn.batch_execute(
467+
conn.simple_query(
468468
"CREATE TYPE pg_temp.inventory_item AS (
469469
name TEXT,
470470
supplier INTEGER,
@@ -491,7 +491,7 @@ fn composite() {
491491
#[test]
492492
fn enum_() {
493493
let conn = Connection::connect("postgres://postgres@localhost:5433", TlsMode::None).unwrap();
494-
conn.batch_execute("CREATE TYPE pg_temp.mood AS ENUM ('sad', 'ok', 'happy');")
494+
conn.simple_query("CREATE TYPE pg_temp.mood AS ENUM ('sad', 'ok', 'happy');")
495495
.unwrap();
496496

497497
let stmt = conn.prepare("SELECT $1::mood").unwrap();

0 commit comments

Comments
 (0)