On this page:
make-data-object
save-data-object
insert-data-object
update-data-object
delete-data-object
select-data-object
select-data-objects
data-object-state
get-column
set-column!
get-join

3 Data Object Persistence

procedure

(make-data-object db-connection    
  data-class    
  primary-key)  (data-object?)
  db-connection : connection?
  data-class : data-class?
  primary-key : (or/c identifier? (list of identifier?))
Loads a data object from the database by primary key.

procedure

(save-data-object db-connection    
  data-object)  (void?)
  db-connection : connection?
  data-object : data-object?
Saves a data object into the database connected to. This will either insert this object into the database, if the object’s state is 'new or update if the object has been previously loaded. The object’s state will be changed to 'saved.

procedure

(insert-data-object db-connection    
  data-object)  (void?)
  db-connection : connection?
  data-object : data-object?
Inserts a data object into the database connected to. The object’s state will be changed to 'saved.

procedure

(update-data-object db-connection    
  data-object)  (void?)
  db-connection : connection?
  data-object : data-object?
Updates a data object into the database connected to. The object’s state will be changed to 'saved.

procedure

(delete-data-object db-connection    
  data-object)  (void?)
  db-connection : connection?
  data-object : data-object?
Deletes a data object from the connected database. The object’s state will be changed to 'deleted.

procedure

(select-data-object db-connection    
  data-class    
  [print-kw    
  prepare-kw]    
  join-clause ...    
  where-clause    
  rest ...)  (data-object?)
  db-connection : connection?
  data-class : data-class?
  print-kw : 
 = #:print? (or/c #t #f)
  prepare-kw : 
 = #:prepare? (or/c #t #f)
  join-clause : any/c
  where-clause : any/c
  rest : any/c
Loads a data object from the database connected to using the criteria defined by the where and/or join RQL clauses. The object’s initial state will be 'loaded.

The optional #:print? keyword if true, will return only the SQL generated from the RQL. This is useful for debugging.

The optional #:prepare? keyword if true, will force the SQL statement generated to not be cached as a prepared statement. This is useful for RQL that may have variable inputs, such a list in an RQL in cause.

The join clauses and and where clauses use RQL defined below. Optionally a SQL string may be used rather than RQL. This may be done in situations where some advanced SQL feature needs to be used that currently cannot be coded in RQL.

procedure

(select-data-objects db-connection    
  data-class    
  [print-kw    
  prepare-kw]    
  join-clause ...    
  where-clause    
  rest ...)  (listof data-object?)
  db-connection : connection?
  data-class : data-class?
  print-kw : 
 = #:print? (or/c #t #f)
  prepare-kw : 
 = #:prepare? (or/c #t #f)
  join-clause : any/c
  where-clause : any/c
  rest : any/c
Loads data objects from the database connected to using the criteria defined by the where and/or join RQL clauses. Each object’s initial state will be 'loaded.

The optional #:print? keyword if true, will return only the SQL generated from the RQL. This is useful for debugging.

The optional #:prepare? keyword if true, will force the SQL statement generated to not be cached as a prepared statement. This is useful for RQL that may have variable inputs, such a list in an RQL in cause.

The join clauses and and where clauses use RQL defined below. Optionally a SQL string may be used rather than RQL. This may be done in situations where some advanced SQL feature needs to be used that currently cannot be coded in RQL.

(select-data-objects con address% "join person p on person-id = p.id \

where lastname in (select lastname from employee where active = 1)")

procedure

(data-object-state data-object)

  (or/c 'new 'loaded 'saved 'deleted 'deserialized)
  data-object : data-object?
Returns the current state of the data object.

procedure

(get-column id data-object)  (any/c)

  id : symbol?
  data-object : data-object?
Gets the value of a data object’s column, analogous to get-field.

procedure

(set-column! id data-object value)  (void?)

  id : symbol?
  data-object : data-object?
  value : any/c
Sets the value of a data object’s column, analogous to set-field!.

procedure

(get-join id data-object)  (or/c any/c (listof any/c))

  id : symbol?
  data-object : data-object?
Gets the value of a data object join. The value of the join field is loaded from the database upon first call. (This is known as "lazy" loading.)