OxL Справочник OxL
РусскийEnglish

src/notes/notes.oxl

oxl
use std.orm { Db }

@table("notes")
pub data Note {
  @pk @auto pub id: i64
  pub title: str
  pub done: bool
}

/// Adds a note and returns its id.
pub fn add(db: &Db, title: str) -> i64  io, db {
  db.insert(Note{ id: 0, title, done: false })
  db.lastInsertId()
}

/// Titles of the notes that are not done, oldest first.
pub fn pending(db: &Db) -> List<str>  io, db {
  let titles = from n in db.Note where! n.done order by n.id select n.title
  titles
}

/// Marks a note as done; false when there is no such note.
pub fn finish(db: &Db, id: i64) -> bool  io, db {
  match db.find(Note, id) {
    Note n => {
      db.update(Note{ id: n.id, title: n.title, done: true })
      true
    }
    _ => false
  }
}

Исходник: examples/notes-orm/src/notes/notes.oxl