-
Notifications
You must be signed in to change notification settings - Fork 3
Home
cowboy parse model files and parse mapper files. and it generate c++ codes.if has no error.
model file is normal c++ header file with extension ".h"
but it first line is //@Models
eg:
//@Models
#pragma once
#include <string>
#include <list>
//@Model
//@Table{customer}
struct customer_t
{
customer_t()
{
id = 0;
int a = 2;
a++;
}
long long int id;
std::string address;
//@Column{postcode}
std::string postcode;
//@Column{sex}
std::string sex;
//@Column{cname}
std::string cname;
};
define model file .cowboy parse model files which first line is //@Models
define a model.
it map to database table name
mapper c++ member variable to database table column. default member variable name is the column name.
eg:
//@Model
struct customer_order_t :customer_t
{
std::list<orders_t> orders;
};
customer_order_t will has all the customer_t's property
mapper file is normal c++ file with extension .h
mapper file first line is //@Mappers.cowboy will scan a directory. all files witch first line is //@Mappers
eg:
//@Mappers
#pragma once
//@Mapper
struct customer_mapper
{
//@Insert{insert into customer(address,postcode,sex,cname)values (:address,:postcode,:sex,:cname)}
virtual bool insert(const customer_t &obj) = 0;
//@Delete{delete from customer where id=:id}
virtual bool delete_by_id(int id) = 0;
//@Update{update customer set address=:address,postcode=:postcode,sex=:sex,cname=:cname where id=:id}
virtual bool update(const customer_t &obj) = 0;
//@Update{update customer set address=:new_address where id=:id}
virtual bool update_address(const customer_t &obj,const std::string &new_address) = 0;
//@Select{select * from customer where id=:id}
virtual bool select_by_id(customer_t &obj, int id) = 0;
};
define a mapper
define insert action interface.
//@Insert{insert into customer(address,postcode,sex,cname)values (:address,:postcode,:sex,:cname)}
virtual bool insert(const customer_t &obj) = 0;
virtual bool insert(const customer_t &obj) = 0; is a interface.
:address,:postcode,:sex,:cname are sql parameters
:address match customer_t::address.
and so on
the same to //@Insert{sql}
the same to //@Insert{sql}
the same to //@Insert{sql}
eg:
//@Select{select c.id as cid,c.address,c.postcode,c.sex,c.cname,o.id as oid,o.code,o.customer_id from customer c, orders o where o.customer_id = c.id and c.cname = :name}
//@Result{column=cid, property=customer.id}
//@Result{column=oid, property=id}
virtual bool get_order_customers_by_name(std::list<order_customer_t> &obj,const std::string & name)=0;
it change order_customer_t::id 's column name to oid. and change order_customer_t::customer::id's column name to ```cid``