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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! A read-only implementation of reading
//! [Realm](https://github.com/realm/realm-swift?tab=readme-ov-file#about-realm-database)
//! database files in Rust.
//!
//! Note that not all features, and in particular all column types, are
//! supported. But for the cases where you only need to _read_ data from a Realm
//! file in Rust, within the current limitations of this library, it may be a
//! more ergonomic alternative than interacting with the [C++
//! SDK](https://github.com/realm/realm-cpp).
//!
//! # Loading a Realm file
//!
//! ```no_run
//! use realm_db_reader::{Group, Realm};
//!
//! let realm = Realm::open("my-database.realm").unwrap();
//! let group = realm.into_group().unwrap();
//! ```
//!
//! At this point, you have a [`Group`] instance, which is the root of the Realm
//! database. You can use it to access the tables and columns within the loaded file.
//!
//! # Reading data from tables
//!
//! ```no_run
//! # use realm_db_reader::{Group, Realm};
//! # let realm = Realm::open("my-database.realm").unwrap();
//! # let group = realm.into_group().unwrap();
//! # let my_objects_table_index = 0;
//! let table = group.get_table_by_name("col_MyObjects").unwrap();
//! // or:
//! let table = group.get_table(my_objects_table_index).unwrap();
//!
//! // Tables allow you to load all rows, a given row based on its index, or
//! // look up a row by an indexed column.
//! // Here, we'll check the total number of rows in the table, and load the
//! // middle one.
//! let row_count = table.row_count().unwrap();
//! let middle_row = table.get_row(row_count / 2).unwrap();
//!
//! let row = table.get_row(0).unwrap();
//! dbg!(row);
//! ```
//!
//! As mentioned, if the table you're interacting with has an indexed column,
//! you can find a row by a known value:
//!
//! ```no_run
//! # use realm_db_reader::{Group, Realm};
//! # let realm = Realm::open("my-database.realm").unwrap();
//! # let group = realm.into_group().unwrap();
//! # let some_id = "";
//! let table = group.get_table_by_name("col_MyObjects").unwrap();
//!
//! let row = table.find_row_from_indexed_column("id", &some_id.into()).unwrap();
//! dbg!(row);
//! ```
//!
//! Here, `row`, will be the _first row_ matching the given value. If no rows
//! match, [`Option::None`] will be returned.
//!
//! # Mapping rows to structs
//!
//! [`Row`] values are relatively low-level, so you may want to map them to your
//! struct for convenience. You can use the [`realm_model`] macro for this.
//!
//! ```no_run
//! # use realm_db_reader::{realm_model, Group, Realm};
//! # let realm = Realm::open("my-database.realm").unwrap();
//! # let group = realm.into_group().unwrap();
//! # let table = group.get_table(0).unwrap();
//! # let row = table.get_row(0).unwrap();
//!
//! struct MyObject {
//! id: String,
//! name: String,
//! }
//!
//! realm_model!(MyObject => id, name);
//!
//! let my_object: MyObject = row.try_into().unwrap();
//! ```
//!
//! Check [the macro documentation](realm_model) for more details.
// Export public types.
pub use Column;
pub use ;
pub use Group;
pub use Realm;
pub use ;
pub use ;