Class DBIRecord[in The DBI Falcon Module.]

Base class for object oriented database access.

class DBIRecord

more...

Summary

_dbhdatabase handle used for this instanc
_persistan optional array of class properties to read from and write to the database
_primaryKeyprimary key used during get and update dat
_tableNamedatabase table name this instance should read from and write t
delete()Delete an object from the database.
insert()Insert a new object into the database
update()Update an existing object in the database.

Detailed description

Base class for object oriented database access.

Rules

All properties begining with an underscore (_) will be ignored. All other properties will be persisted during a DBIRecord.insert or DBIRecord.update unless the property _persist is defined. If _persist is defined, then all properties will be ignored except those in the _persist array.

In the below example, the class Person, does not need to define the _persist property as it has no special attributes. It was included as an example of how to define the _persist property.

    load dbi

    class Person( nName, nDob ) from DBIRecord
       _tableName = "names"
       _primaryKey = "name"
       _persist = ["name", "dob"]

       name = nName
       dob = nDob
    end

    db = DBIConnect( "sqlite3:example.db" )
    Person( "John Doe", TimeStamp() ).insert()
    Person( "Jane Doe", TimeStamp() ).insert()

    r = db.query( "SELECT * FROM names" )
    while (n = r.fetchObject( Person() ))
      > n.name, " was born on ", n.dob
      n.name = n.name + "ey"
      n.update()
    end
    r.close()
    db.close()

You can of course expand the Person class with more properties and also methods which are not persisted, such as a method to calculate the age of the person, or to determine if today is their birthday which in turn would show the real power of using the DBIRecord object method.

Properties

_dbh

database handle used for this instanc

_persist

an optional array of class properties to read from and write to the database

_primaryKey

primary key used during get and update dat

_tableName

database table name this instance should read from and write t

Methods

delete()

Delete an object from the database.

DBIRecord.delete( )

insert()

Insert a new object into the database

DBIRecord.insert( )

update()

Update an existing object in the database.

DBIRecord.update( )


Made with faldoc 2.0.0