Skip to content
Aman Kumar edited this page May 12, 2023 · 5 revisions

single_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.

Salient features of single_crud:

  • 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)

crud_factory

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');

signgle_crud_factory.new({msg_ns, msg_elem_name, db_name, tbl_name});

DESCRIPTION:

Constructs the single record crud object for the specified table name in the specified db

PARAMETERS:

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 table

RETURN:

single_crud_object: table, handle to perform operations on a single record of the specified table.

ERROR:

Throws exception if anything goes wrong

single_crud_object:

A lua object created for a given table name and database

local table_access_object = signgle\_crud\_factory.new(context, db_name, table_name);

single_crud_object:fetch(context, query_params);

DESCRIPTION:

Performs FETCH operation on the table using the key passed in the variable arguments of the function

PARAMETERS:

context: table, user_context
query_params: table, Set of key fields needed to perform the fetch operation

RETURN:

status: boolean, true if successful record_obj: table, the record is returned in case of success, else second argument will bear the error message

ERROR:

Throws exceptions if any

single_crud_object:add(context, obj);

DESCRIPTION:

Performs ADD operation on the table using the key passed in the variable arguments of the function

PARAMETERS:

context: table, user_context
obj: table, the lua object which is being used in the calling program

RETURN:

status: 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 error

ERROR:

Duplicate Record found for .

single_crud_object:modify(context, obj);

DESCRIPTION:

Performs MODIFY operation on the table using the key passed in the variable arguments of the function

PARAMETERS:

context: table, user_context
obj: table, the lua object which is being used in the calling program

RETURN:

status: 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 condition

ERROR:

Any exceptions are thrown

single_crud_object:phydel(context, obj);

DESCRIPTION:

Performs PHYSICAL DELETE operation on the table using the key passed in the variable arguments of the function

PARAMETERS:

context: table, user_context
obj: table, the lua object which is being used in the calling program

RETURN:

status: 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 condition

ERROR:

Any exceptions are thrown

single_crud_object:delete(context, obj);

DESCRIPTION:

Performs LOGICAL/PHYSICAL DELETE (based on table spec) operation on the table using the key passed in the variable arguments of the function

PARAMETERS:

context: table, user_context
obj: table, the lua object which is being used in the calling program

RETURN:

status: 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 condition

ERROR:

Any exceptions are thrown

single_crud_object:logdel(context, obj);

DESCRIPTION:

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

PARAMETERS:

context: table, user_context
obj: table, the lua object which is being used in the calling program

RETURN:

status: 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 condition

ERROR:

Any exceptions are thrown

single_crud_object:undelete(context, obj);

DESCRIPTION:

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

PARAMETERS:

context: table, user_context
obj: table, the lua object which is being used in the calling program

RETURN:

status: 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 condition

ERROR:

Any exceptions are thrown

Clone this wiki locally