Skip to main content

Note

Struct Note 

Source
pub struct Note { /* private fields */ }
Expand description

A note from Bear’s database.

§Nullable Fields

Only one field in Bear notes can be NULL in the database:

  • content: Empty notes may have None for content.

§Always-Present Fields

The following fields are always present (never NULL):

  • title: All notes have titles (may be empty string, but never NULL)
  • unique_id: Bear’s UUID identifier (always present)
  • id: Primary key (always present)
  • modified, created: Timestamps (always present)
  • is_pinned: Boolean flag (always present)

§Identifiers

Bear notes use UUIDs as their primary identifier:

§UUID (id())

  • Type: &NoteId (Bear’s UUID like ‘ABC123-DEF456-…’)
  • Always present (never NULL)
  • Stable across the lifetime of the note and across devices
  • Use this for all programmatic references and API calls
  • Bear uses this for syncing and x-callback-url schemes
  • Used in Bear’s x-callback-url API (e.g., bear://x-callback-url/open-note?id=UUID)

The internal Core Data primary key is not exposed in the public API.

§Example

let db = BearDb::new()?;
let notes = db.notes(NotesQuery::default())?;

for note in notes {
    let note_id = note.id();
    let title = note.title();

    // Only content may be None
    let content = note.content().unwrap_or("");

    println!("Note {}: {} ({} bytes)", note_id.as_str(), title, content.len());
}

Implementations§

Source§

impl Note

Source

pub fn id(&self) -> &NoteId

Returns the note’s Bear identifier.

This is Bear’s UUID identifier, which is:

  • Always present (never NULL)
  • Stable across the note’s lifetime
  • Works across devices (syncing)
  • Used in Bear’s x-callback-url API

Use this for:

  • Opening notes in Bear
  • Storing references to notes
  • Matching notes across devices
§Example
let note_id = note.id();
println!("Open in Bear: bear://x-callback-url/open-note?id={}", note_id.as_str());
Examples found in repository?
examples/query_demo.rs (line 17)
3fn main() -> Result<(), BearError> {
4  let db = BearDb::new()?;
5
6  // Example 1: Using typed API
7  println!("=== Typed API Examples ===\n");
8
9  let tags = db.tags()?;
10  println!("Total tags: {}\n", tags.count());
11
12  // Using the new NotesQuery API - much more readable!
13  db.notes(NotesQuery::default())?
14    .into_iter()
15    .for_each(|note| {
16      println!("Note: {:?}", note.title());
17      db.note_links(note.id())
18        .unwrap()
19        .into_iter()
20        .for_each(|link| println!("  Linked: {:?}", link.title()));
21
22      let note_tags = db.note_tags(note.id()).unwrap();
23      println!("  Tags: {:?}\n", tags.names(&note_tags));
24    });
25
26  // Example 2: Using generic SQL query API with DataFrames
27  println!("\n=== Generic SQL Query API Examples ===\n");
28
29  // Simple query
30  println!("Top 5 most recent notes:");
31  let df = db
32    .query("SELECT title, created FROM notes WHERE is_trashed = 0 ORDER BY created DESC LIMIT 5")?;
33  println!("{}\n", df);
34
35  // Join query
36  println!("Notes with their tags:");
37  let df = db.query(
38    r"
39    SELECT n.title, t.name as tag_name
40    FROM notes n
41    JOIN note_tags nt ON n.id = nt.note_id
42    JOIN tags t ON nt.tag_id = t.id
43    WHERE n.is_trashed = 0
44    ORDER BY n.modified DESC
45    LIMIT 10
46  ",
47  )?;
48  println!("{}\n", df);
49
50  // Aggregation query
51  println!("Tag usage statistics:");
52  let df = db.query(
53    r"
54    SELECT t.name, COUNT(*) as note_count
55    FROM tags t
56    JOIN note_tags nt ON t.id = nt.tag_id
57    GROUP BY t.id, t.name
58    ORDER BY note_count DESC
59    LIMIT 10
60  ",
61  )?;
62  println!("{}\n", df);
63
64  Ok(())
65}
Source

pub fn title(&self) -> &str

Returns the note’s title.

All notes have titles (this is never NULL), though the title may be an empty string.

§Example
let title = note.title();
if title.is_empty() {
    println!("[Untitled]");
} else {
    println!("Title: {}", title);
}
Examples found in repository?
examples/query_demo.rs (line 16)
3fn main() -> Result<(), BearError> {
4  let db = BearDb::new()?;
5
6  // Example 1: Using typed API
7  println!("=== Typed API Examples ===\n");
8
9  let tags = db.tags()?;
10  println!("Total tags: {}\n", tags.count());
11
12  // Using the new NotesQuery API - much more readable!
13  db.notes(NotesQuery::default())?
14    .into_iter()
15    .for_each(|note| {
16      println!("Note: {:?}", note.title());
17      db.note_links(note.id())
18        .unwrap()
19        .into_iter()
20        .for_each(|link| println!("  Linked: {:?}", link.title()));
21
22      let note_tags = db.note_tags(note.id()).unwrap();
23      println!("  Tags: {:?}\n", tags.names(&note_tags));
24    });
25
26  // Example 2: Using generic SQL query API with DataFrames
27  println!("\n=== Generic SQL Query API Examples ===\n");
28
29  // Simple query
30  println!("Top 5 most recent notes:");
31  let df = db
32    .query("SELECT title, created FROM notes WHERE is_trashed = 0 ORDER BY created DESC LIMIT 5")?;
33  println!("{}\n", df);
34
35  // Join query
36  println!("Notes with their tags:");
37  let df = db.query(
38    r"
39    SELECT n.title, t.name as tag_name
40    FROM notes n
41    JOIN note_tags nt ON n.id = nt.note_id
42    JOIN tags t ON nt.tag_id = t.id
43    WHERE n.is_trashed = 0
44    ORDER BY n.modified DESC
45    LIMIT 10
46  ",
47  )?;
48  println!("{}\n", df);
49
50  // Aggregation query
51  println!("Tag usage statistics:");
52  let df = db.query(
53    r"
54    SELECT t.name, COUNT(*) as note_count
55    FROM tags t
56    JOIN note_tags nt ON t.id = nt.tag_id
57    GROUP BY t.id, t.name
58    ORDER BY note_count DESC
59    LIMIT 10
60  ",
61  )?;
62  println!("{}\n", df);
63
64  Ok(())
65}
Source

pub fn content(&self) -> Option<&str>

Returns the note’s content (Markdown), if present.

Returns None for empty notes or notes with NULL content.

§Example
let content = note.content().unwrap_or("");
println!("Content length: {} bytes", content.len());
Source

pub fn modified(&self) -> OffsetDateTime

Returns the timestamp of the note’s last modification.

This is always present (never NULL).

Source

pub fn created(&self) -> OffsetDateTime

Returns the timestamp when the note was created.

This is always present (never NULL).

Source

pub fn is_pinned(&self) -> bool

Returns whether the note is pinned.

This is always present (never NULL).

Trait Implementations§

Source§

impl Debug for Note

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Note

§

impl RefUnwindSafe for Note

§

impl Send for Note

§

impl Sync for Note

§

impl Unpin for Note

§

impl UnsafeUnpin for Note

§

impl UnwindSafe for Note

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V