Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Difference From sqlsrv-0.0.4 To sqlsrv-0.1.0
2024-01-24
| ||
17:23 | Add means to register ro or wr connection SQL functions. check-in: a8fb47cff8 user: jan tags: trunk | |
2024-01-21
| ||
17:32 | Release maintenance. check-in: 161dbe5b26 user: jan tags: sqlsrv-0.1.0, trunk | |
17:27 | Introduce a tpool feature to enable/disable threadpool support. check-in: cb6654deac user: jan tags: trunk | |
16:37 | Make internal thread pool optional. check-in: 822036d2f6 user: jan tags: trunk | |
2024-01-19
| ||
16:01 | Release maintenance. check-in: 2a13622830 user: jan tags: sqlsrv-0.0.4, trunk | |
15:58 | Allow dirt to be optionally returned from read/write threaded wrappers. check-in: 03fc406b35 user: jan tags: trunk | |
Changes to Cargo.toml.
1 2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | - + + + + + + - - + + + - + | [package] name = "sqlsrv" |
Added build_docs.sh.
|
Changes to examples/simple.rs.
︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | + + + + + + + + + + - + + + + + | id INTEGER PRIMARY KEY, data TEXT UNIQUE NOT NULL, ts DATETIME DEFAULT CURRENT_TIMESTAMP, CHECK (length(data) == 64) );", &[] as &[&dyn ToSql] )?; conn.execute( "CREATE TABLE IF NOT EXISTS whoop ( id INTEGER PRIMARY KEY, name TEXT, ts DATETIME DEFAULT CURRENT_TIMESTAMP );", &[] as &[&dyn ToSql] )?; } Ok(()) } } fn main() { let schema = Box::new(Schema {}); #[allow(unused_mut)] |
︙ | |||
106 107 108 109 110 111 112 113 114 115 | 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | + + + + + + + + + + + + + + + + + + + | let rconn = connpool.reader().unwrap(); let mut stmt = rconn.prepare_cached(SQL_LOOKUP_TABLE).unwrap(); let have = stmt .query_row(params!("stuff"), |row| row.get::<usize, bool>(0)) .unwrap(); assert!(have); } #[cfg(feature = "tpool")] connpool .ro_run(|conn| { const SQL: &str = "SELECT * FROM snarks;"; let mut _stmt = conn.prepare_cached(SQL).unwrap(); }) .unwrap(); #[cfg(feature = "tpool")] connpool.rw_run(|conn| { const SQL: &str = "INSERT INTO whoop (name) VALUES (?);"; let mut stmt = conn.prepare_cached(SQL).unwrap(); stmt.execute(params!["test"]).unwrap(); Some(1) }); #[cfg(feature = "tpool")] connpool.shutdown(); } // vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 : |
Changes to src/lib.rs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | + + + + + + + | //! A library for implementing an in-process SQLite database server. //! //! # Connection pooling //! sqlsrv implements connection pooling that reflects the concurrency model //! for SQLite: It supports only one writer but multiple readers. //! //! # Connection task pooling //! In addition to pooling connections, the library can pool threads to run //! database operations on. //! //! # Incremental auto-clean //! The connection pool has built-in support for setting up incremental //! autovacuum, and can be configured to implicitly run incremental vacuuming. //! //! To use this feature, a "maximum dirt" value is configured on the connection //! pool. Whenever the writer connection performs changes to the database it //! can add "dirt" to the connection. When the writer connection is returned //! to the connection pool it checks to see if the amount of dirt is equal to //! or greater than the configured "maximum dirt" threshold. If the threshold //! has been reached, an incremental autovacuum is performed. #![cfg_attr(docsrs, feature(doc_cfg))] mod changehook; mod err; mod rawhook; mod wrconn; use std::{ mem::ManuallyDrop, num::NonZeroUsize, path::Path, str::FromStr, sync::Arc }; use parking_lot::{Condvar, Mutex}; use r2d2::{CustomizeConnection, PooledConnection}; use r2d2_sqlite::SqliteConnectionManager; pub use rusqlite; use rusqlite::{params, Connection, OpenFlags}; #[cfg(feature = "tpool")] use threadpool::ThreadPool; pub use changehook::ChangeLogHook; pub use err::Error; pub use rawhook::{Action, Hook}; pub use wrconn::WrConn; |
︙ | |||
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | + + + + + + + + + + + + | conn.pragma_update(None, "foreign_keys", "ON")?; Ok(()) } fn on_release(&self, _conn: rusqlite::Connection) {} } #[cfg(feature = "tpool")] #[derive(Default)] enum ThrdPool { #[default] Disable, Enable { nthreads: Option<usize> } } /// Builder for constructing a [`ConnPool`] object. pub struct Builder { schmgr: Box<dyn SchemaMgr>, full_vacuum: bool, max_readers: usize, #[cfg(feature = "tpool")] thrdpool: ThrdPool, autoclean: Option<AutoClean>, hook: Option<Arc<dyn Hook + Send + Sync>> } /// Internal methods. impl Builder { /// Open the writer connection. |
︙ | |||
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | + + + + + + + + + + + + + + + + + + + | let roconn_initterm = RoConn {}; let max_readers = u32::try_from(self.max_readers).unwrap(); r2d2::Pool::builder() .max_size(max_readers) .connection_customizer(Box::new(roconn_initterm)) .build(manager) } #[cfg(feature = "tpool")] fn init_tpool(&self) -> Option<ThreadPool> { match self.thrdpool { ThrdPool::Disable => None, ThrdPool::Enable { nthreads } => { let nthreads = if let Some(nthreads) = nthreads { nthreads } else { self.max_readers + 1 }; let tpool = ThreadPool::new(nthreads); Some(tpool) } } } } impl Builder { /// Create a new `Builder` for constructing a [`ConnPool`] object. /// /// Default to not run a full vacuum of the database on initialization and /// create 2 read-only connections for the pool. /// No workers thread pool will be used. pub fn new(schmgr: Box<dyn SchemaMgr>) -> Self { Self { schmgr, full_vacuum: false, max_readers: 2, #[cfg(feature = "tpool")] thrdpool: ThrdPool::default(), autoclean: None, hook: None } } /// Trigger a full vacuum when initializing the connection pool. /// |
︙ | |||
206 207 208 209 210 211 212 213 214 215 216 217 218 219 | 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | /// Set maximum number of readers in the connection pool. /// /// Operates on a borrowed `Builder` object. pub fn max_readers_r(&mut self, n: usize) -> &mut Self { self.max_readers = n; self } /// Enable a thread pool for running connection tasks on. /// /// Unless this is called, no thread pool will be allocated and the /// [`ConnPool::ro_run()`] and [`ConnPool::rw_run()`] (and associated /// methods) will panic. /// /// The `nthreads` can be used to specify the number of worker threads to /// allocate. If this is `None`, the number of threads will default to the /// number of reader connections plus one (for the writer). /// /// # Panic /// Panics if `nthreads` is set to `Some(0)`. #[cfg(feature = "tpool")] #[cfg_attr(docsrs, doc(cfg(feature = "tpool")))] pub fn worker_threads(mut self, nthreads: Option<usize>) -> Self { self.worker_threads_r(nthreads); self } /// Enable a thread pool for running connection tasks on. /// /// This does the same as [`Builder::worker_threads()`], but operates on a /// borrowed object. #[cfg(feature = "tpool")] #[cfg_attr(docsrs, doc(cfg(feature = "tpool")))] pub fn worker_threads_r(&mut self, nthreads: Option<usize>) -> &mut Self { assert_ne!(nthreads, Some(0)); self.thrdpool = ThrdPool::Enable { nthreads }; self } /// Request that a "raw" update hook be added to the writer connection. /// /// Operates on an owned `Builder` object. pub fn hook(mut self, hook: Arc<dyn Hook + Send + Sync>) -> Self { self.hook = Some(hook); self |
︙ | |||
284 285 286 287 288 289 290 | 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | - + + - + - + + + + + + | // Register a callback hook // if let Some(ref hook) = self.hook { rawhook::hook(&conn, Arc::clone(hook)); } // |
︙ | |||
371 372 373 374 375 376 377 | 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | - + + - + - + + + + + + | // // Register a callback hook // changehook::hook(&conn, hook); // |
︙ | |||
433 434 435 436 437 438 439 | 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | + - + | /// SQLite connection pool. /// /// This is a somewhat specialized connection pool that only allows a single /// writer but multiple readers. pub struct ConnPool { sh: Arc<Shared>, rpool: r2d2::Pool<SqliteConnectionManager>, #[cfg(feature = "tpool")] |
︙ | |||
481 482 483 484 485 486 487 488 489 490 491 492 493 | 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 | + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + - + - + + + + + + + + + - + + + + + + - + + | Some(WrConn { sh: Arc::clone(&self.sh), inner: ManuallyDrop::new(conn) }) } /// Run a closure with a read-only connection /// /// # Panic /// Panics if the connection pool was not configured to use a thread pool. #[cfg(feature = "tpool")] #[cfg_attr(docsrs, doc(cfg(feature = "tpool")))] pub fn ro_run<F>(&self, f: F) -> Result<(), r2d2::Error> where F: FnOnce(&Connection) + Send + 'static { let Some(ref tpool) = self.tpool else { panic!("Connection pool does not have a thread pool"); }; let roconn = self.reader()?; |
Changes to www/changelog.md.
1 2 3 4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | - + + + + + + + + + + + + + - + | # Change Log ## [Unreleased] |
︙ |