-
Notifications
You must be signed in to change notification settings - Fork 5
CRUD
An interface to achieve CREATE, READ, UPDATE and DELETE of a single record business entity represented by a table record in RDBMS
In order to use single_crud, a table spec (an XML complying to table definition spec) coded and the tool gtbl run with table-spec as argument. With this a set of lua classes get generated with SQL statements and other details
single_crud uses the generated lua classes to provide an inteface to the calling program.
- Built over TAO, thus it supports all the features of TAO (logical delete, optimistic locking etc.)
- The instantiation requires a schema definition (namespace, name) which will be used to map columns of the table to the elements in the iput object
- Encapsulates TAO and exposes methods add, fetch, modify, delete (CRUD)
- TBD: Audit of operations on the record of a table.
- TBD: Support for maker-checker (workflow)
The caller instantiates a factory object and uses the factory to create table specific CRUD classes, which are further used to perform the ADD, MODIFY, FETCH, DELETE and UNDELETE operations
local single_crud = require('service_utils.orm.single_crud_factory');
Constructs the single record crud object for the specified table name in the specified db
crud_params: table, members are class_name: string, name of the class calling the open method
msg_ns: string, namespace of the element declaration in the schema
msg_elem_name: string, name of the element declaration in the schema
db_name: string, name of the database
tbl_name: string, name of the database tablesingle_crud_object: table, handle to perform operations on a single record of the specified table.
Throws exception if anything goes wrong
A lua object created for a given table name and database
local table_access_object = signgle\_crud\_factory.new(context, db_name, table_name);
Performs FETCH operation on the table using the key passed in the variable arguments of the function
context: table, user_context
query_params: table, Set of key fields needed to perform the fetch operationstatus: boolean, true if successful record_obj: table, the record is returned in case of success, else second argument will bear the error message
Throws exceptions if any
Performs ADD operation on the table using the key passed in the variable arguments of the function
context: table, user_context
obj: table, the lua object which is being used in the calling programstatus: boolean, true if successful
msg: string, will contain error message in case status is returned as false
ret: integer, 0 => successful, -1 => duplicate record, -2 => any other errorDuplicate Record found for .
Performs MODIFY operation on the table using the key passed in the variable arguments of the function
context: table, user_context
obj: table, the lua object which is being used in the calling programstatus: boolean, true if successful
msg: string, if status is false (unsuccessful update) the error message is returned here
ret: integer, 0 => where clause did not match any record, >0 => number of records updated, -1 => error conditionAny exceptions are thrown
Performs PHYSICAL DELETE operation on the table using the key passed in the variable arguments of the function
context: table, user_context
obj: table, the lua object which is being used in the calling programstatus: boolean, true if successful
msg: string, if status is false (unsuccessful delete) the error message is returned here
ret: integer, 0 => where clause did not match any record, >0 => number of records deleted, -1 => error conditionAny exceptions are thrown
Performs LOGICAL/PHYSICAL DELETE (based on table spec) operation on the table using the key passed in the variable arguments of the function
context: table, user_context
obj: table, the lua object which is being used in the calling programstatus: boolean, true if successful
msg: string, if status is false (unsuccessful delete) the error message is returned here
ret: integer, 0 => where clause did not match any record, >0 => number of records deleted, -1 => error conditionAny exceptions are thrown
Performs LOGICAL DELETE (based on table spec) operation on the table using the key passed in the variable arguments of the function, if logical delete is not possible, error is thrown
context: table, user_context
obj: table, the lua object which is being used in the calling programstatus: boolean, true if successful
msg: string, if status is false (unsuccessful delete) the error message is returned here
ret: integer, 0 => where clause did not match any record, >0 => number of records deleted, -1 => error conditionAny exceptions are thrown
Performs UNDELETE (based on table spec) operation on the table using the key passed in the variable arguments of the function, if logical undelete is not possible, error is thrown
context: table, user_context
obj: table, the lua object which is being used in the calling programstatus: boolean, true if successful
msg: string, if status is false (unsuccessful undelete) the error message is returned here
ret: integer, 0 => where clause did not match any record, >0 => number of records deleted, -1 => error conditionAny exceptions are thrown