Build a typed database by defining a struct
Build a typed database by defining a struct
This is a very simple framework to be able to access database rows as objects without forcing you to inherit from a Model class. Instead you create the class-hierarchy you want and use mixin to add persistance functionality to the object.
DBStruct is a class that, like Struct, provides a convenient way to create subclasses with named fields that can be accessed via the usual Ruby setters and getters. Unlike Struct, their contents are stored in a SQLite3 database. In addition, each subclass also provides access to the database via an interface that closely mimics a Ruby Hash, including support for enumeration.