oRm is a lightweight ORM for R. Define models, insert data, and query relationships without writing raw SQL.
🔧 Installation
remotes::install_github("kent-orr/oRm")
🚀 Quickstart
2. Define Models
User <- engine$model(
"users",
id = Column("INTEGER", primary_key = TRUE, nullable = FALSE),
organization_id = ForeignKey("INTEGER", references = "organizations.id"),
name = Column("TEXT", nullable = FALSE),
age = Column("INTEGER")
)
Organization <- engine$model(
"organizations",
id = Column("INTEGER", primary_key = TRUE, nullable = FALSE),
name = Column("TEXT", nullable = FALSE)
)
Organization$create_table()
User$create_table()
3. Add Relationship
User |> define_relationship(
local_key = "organization_id",
type = "belongs_to",
related_model = Organization,
related_key = "id",
ref = "organization",
backref = "users"
)
4. Insert Records
Organization$record(id = 1L, name = "Widgets, Inc")$create()
User$record(id = 1L, organization_id = 1L, name = "Kent", age = 34)$create()
User$record(id = 2L, organization_id = 1L, name = "Dylan", age = 25)$create()