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 and Restoration🔗ℹ

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? print-sql    
  #:prepare? prepare-sql]    
  select-criteria)  (data-object?)
  db-connection : connection?
  data-class : data-class?
  print-sql : (or/c #t #f) = #f
  prepare-sql : (or/c #t #f) = #f
  select-criteria : 
(or/c [rql-criteria (listof [join-clause any/c] ...
                            [where-clause any/c]
                            [rest any/c] ...)]
      [sql-criteria string?])
Loads a data object from the connected database using the criteria defined by either the where and/or join RQL clauses, or by a string containing SQL 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 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? print-sql 
  #:prepare? prepare-sql] 
  select-criteria) 
  (listof data-object?)
  db-connection : connection?
  data-class : data-class?
  print-sql : (or/c #t #f) = #f
  prepare-sql : (or/c #t #f) = #f
  select-criteria : 
(or/c [rql-criteria (listof [join-clause any/c] ...
                            [where-clause any/c]
                            [rest any/c] ...)]
      [sql-criteria string?])
Loads data objects from the connected database using the criteria defined by either the where and/or join RQL clauses, or by a string containing SQL 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 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.)