sqlsrv

Check-in Differences
Login

Check-in Differences

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Difference From sqlsrv-0.0.1 To sqlsrv-0.0.2

2024-01-14
11:23
Update changelog. check-in: 8a035d3c3d user: jan tags: trunk
11:18
Dependency maintenance. check-in: faa6fca725 user: jan tags: sqlsrv-0.0.2, trunk
2024-01-11
13:01
Update changelog. check-in: 1657f3c0fc user: jan tags: trunk
12:55
Re-export rusqlite. check-in: 09bf302308 user: jan tags: trunk
2024-01-09
12:47
Happy Clippy. check-in: 4eb07f3dd9 user: jan tags: sqlsrv-0.0.1, trunk
12:45
Move from old repo. check-in: 0130f34b3a user: jan tags: trunk

Changes to Cargo.toml.

1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







[package]
name = "sqlsrv"
version = "0.0.1"
version = "0.0.2"
edition = "2021"
license = "0BSD"
categories = [ "database" ]
keywords = [ "sqlite", "server" ]
repository = "https://repos.qrnch.tech/pub/sqlsrv"
description = "Utility functions for managing SQLite connections in a server application."
rust-version = "1.56"
18
19
20
21
22
23
24
25

26
27
28
29
30
18
19
20
21
22
23
24

25
26
27
28
29
30







-
+





]

[dependencies]
parking_lot = { version = "0.12.1" }
r2d2 = { version = "0.8.10" }
r2d2_sqlite = { version = "0.23.0" }
rusqlite = { version = "0.30.0", features = ["hooks"] }
swctx = { version = "0.2.1" }
swctx = { version = "0.2.2" }
threadpool = { version = "1.8.1" }

[package.metadata.docs.rs]
rustdoc-args = ["--generate-link-to-definition"]

Changes to examples/simple.rs.

1
2
3
4
5
6
7




8

9
10
11
12
13
14
15
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19







+
+
+
+
-
+







use rusqlite::{params, Connection, ToSql};

use sqlsrv::SchemaMgr;

struct Schema {}

impl SchemaMgr for Schema {
  fn init(
    &self,
    conn: &mut Connection,
    newdb: bool
  fn init(&self, conn: &Connection, newdb: bool) -> Result<(), sqlsrv::Error> {
  ) -> Result<(), sqlsrv::Error> {
    if newdb {
      conn.execute(
        "CREATE TABLE IF NOT EXISTS snarks (
  id   INTEGER  PRIMARY KEY,
  data TEXT     UNIQUE NOT NULL,
  ts   DATETIME DEFAULT CURRENT_TIMESTAMP,
  CHECK (length(data) == 64)

Changes to src/lib.rs.

25
26
27
28
29
30
31


32
33
34
35
36
37
38
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40







+
+







};

use parking_lot::{Condvar, Mutex};

use r2d2::{CustomizeConnection, PooledConnection};

use r2d2_sqlite::SqliteConnectionManager;

pub use rusqlite;

use rusqlite::{params, Connection, OpenFlags};

use threadpool::ThreadPool;

pub use changehook::ChangeLogHook;
pub use err::Error;
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86







-
+


















-
+







  ///
  /// While this method can be used to perform schema upgrades, there are two
  /// specialized methods (`need_upgrade()` and `upgrade()`) that can be used
  /// for this purpose instead.
  ///
  /// The default implementation does nothing but returns `Ok(())`.
  #[allow(unused_variables)]
  fn init(&self, conn: &Connection, newdb: bool) -> Result<(), Error> {
  fn init(&self, conn: &mut Connection, newdb: bool) -> Result<(), Error> {
    Ok(())
  }

  /// Application callback used to determine if the database schema is out of
  /// date and needs to be updated.
  ///
  /// The default implementation does nothing but returns `Ok(false)`.
  #[allow(unused_variables)]
  fn need_upgrade(&self, conn: &Connection) -> Result<bool, Error> {
    Ok(false)
  }

  /// Upgrade the database schema.
  ///
  /// This is called if [`SchemaMgr::need_upgrade()`] returns `Ok(true)`.
  ///
  /// The default implementation does nothing but returns `Ok(())`.
  #[allow(unused_variables)]
  fn upgrade(&self, conn: &Connection) -> Result<(), Error> {
  fn upgrade(&self, conn: &mut Connection) -> Result<(), Error> {
    Ok(())
  }
}


#[derive(Clone, Debug)]
struct AutoClean {
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
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







-
+








-
+

-
+








    //
    // Set up the read/write connection
    //
    // This must be done before creating the read-only connection pool, because
    // at that point the database file must already exist.
    //
    let conn = self.open_writer(fname)?;
    let mut conn = self.open_writer(fname)?;

    //
    // Perform schema initialization.
    //
    // This must be done after auto_vacuum is set, because auto_vacuum requires
    // configuration before any tables have been created.
    // See: https://www.sqlite.org/pragma.html#pragma_auto_vacuum
    //
    self.schmgr.init(&conn, !db_exists)?;
    self.schmgr.init(&mut conn, !db_exists)?;
    if self.schmgr.need_upgrade(&conn)? {
      self.schmgr.upgrade(&conn)?;
      self.schmgr.upgrade(&mut conn)?;
    }

    //
    // Perform a full vacuum if requested to do so.
    //
    if self.full_vacuum {
      self.full_vacuum(&conn)?;
342
343
344
345
346
347
348
349

350
351
352
353
354
355
356
357
358

359
360

361
362
363
364
365
366
367
344
345
346
347
348
349
350

351
352
353
354
355
356
357
358
359

360
361

362
363
364
365
366
367
368
369







-
+








-
+

-
+








    //
    // Set up the read/write connection
    //
    // This must be done before creating the read-only connection pool, because
    // at that point the database file must already exist.
    //
    let conn = self.open_writer(fname)?;
    let mut conn = self.open_writer(fname)?;

    //
    // Perform schema initialization.
    //
    // This must be done after auto_vacuum is set, because auto_vacuum requires
    // configuration before any tables have been created.
    // See: https://www.sqlite.org/pragma.html#pragma_auto_vacuum
    //
    self.schmgr.init(&conn, !db_exists)?;
    self.schmgr.init(&mut conn, !db_exists)?;
    if self.schmgr.need_upgrade(&conn)? {
      self.schmgr.upgrade(&conn)?;
      self.schmgr.upgrade(&mut conn)?;
    }

    //
    // Perform a full vacuum if requested to do so.
    //
    if self.full_vacuum {
      self.full_vacuum(&conn)?;

Changes to www/changelog.md.

1
2
3
4


5
6


7


8
9
10
11
12
13
14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20




+
+


+
+

+
+







# Change Log

## [Unreleased]

[Details](/vdiff?from=sqlsrv-0.0.1&to=trunk)

### Added

- Re-export rusqlite.

### Changed

- Pass mutable `Connection` to schema handler's `init()` and `upgrade()`.

### Removed

---

## [0.0.1] - 2024-01-09