sqlite_rs/pager/
page.rs

1//! # Pages
2//!
3//!  The main database file consists of one or more pages. The size of a page is
4//! a power of two between 512 and 65536 inclusive. All pages within the same
5//! database are the same size. The page size for a database file is determined
6//! by the 2-byte integer located at an offset of 16 bytes from the beginning of
7//! the database file.
8//!
9//!  Pages are numbered beginning with 1. The maximum page number is 4294967294
10//! (232 - 2). The minimum size SQLite database is a single 512-byte page. The
11//! maximum size database would be 4294967294 pages at 65536 bytes per page or
12//! 281,474,976,579,584 bytes (about 281 terabytes). Usually SQLite will hit the
13//! maximum file size limit of the underlying filesystem or disk hardware long
14//! before it hits its own internal size limit.
15//!
16//!  In common use, SQLite databases tend to range in size from a few kilobytes
17//! to a few gigabytes, though terabyte-size SQLite databases are known to exist
18//! in production.
19//!
20//!  At any point in time, every page in the main database has a single use
21//! which is one of the following:
22//!
23//! - The lock-byte page
24//! - A freelist page
25//!     - A freelist trunk page
26//!     - A freelist leaf page
27//! - A b-tree page
28//!     - A table b-tree interior page
29//!     - A table b-tree leaf page
30//!     - An index b-tree interior page
31//!     - An index b-tree leaf page
32//! - A payload overflow page
33//! - A pointer map page
34//!
35//!  All reads from and writes to the main database file begin at a page
36//! boundary and all writes are an integer number of pages in size. Reads are
37//! also usually an integer number of pages in size, with the one exception that
38//! when the database is first opened, the first 100 bytes of the database file
39//! (the database file header) are read as a sub-page size unit.
40//!
41//!  Before any information-bearing page of the database is modified, the
42//! original unmodified content of that page is written into the rollback
43//! journal. If a transaction is interrupted and needs to be rolled back, the
44//! rollback journal can then be used to restore the database to its original
45//! state. Freelist leaf pages bear no information that would need to be
46//! restored on a rollback and so they are not written to the journal prior to
47//! modification, in order to reduce disk I/O.
48//!
49//! *Reference:* https://www.sqlite.org/fileformat2.html#pages
50
51use crate::header::PageSize;
52
53#[derive(Debug)]
54pub struct Page {
55  pub length: PageSize,
56  pub raw_data: Vec<u8>,
57}
58
59impl Page {
60  pub const MAX_LENGTH: usize = PageSize::MAX.as_usize();
61
62  pub fn length(&self) -> &PageSize {
63    &self.length
64  }
65
66  pub fn raw_data(&self) -> &Vec<u8> {
67    &self.raw_data
68  }
69}