Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func CreateApplyLeaveTable() string {
- applyLeaveTable := `CREATE TABLE apply_leave1 (
- leaveid serial PRIMARY KEY NOT NULL ,
- empid varchar(10) NOT NULL ,
- leavedays double precision NOT NULL DEFAULT 0 ,
- mdays double precision NOT NULL DEFAULT 0 ,
- leavetype varchar(20) NOT NULL DEFAULT '' ,
- daytype text NOT NULL '',
- leavefrom timestamp with time zone NOT NULL,
- leaveto timestamp with time zone NOT NULL,
- applieddate timestamp with time zone NOT NULL,
- leavestatus varchar(15) NOT NULL DEFAULT '' ,
- resultdate timestamp with time zone,
- certificatestatus bool NOT NULL DEFAULT FALSE
- certificate json NULL)`
- return applyLeaveTable
- }
- import(
- "database/sql"
- "fmt"
- _"github.com/lib/pq"
- )
- func (e *EmployeeController) Leave() {
- conn := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable",
- "postgres", "root", "employee")
- log.Println("Creating a new connection: %v", conn)
- db, err := sql.Open("postgres", conn)
- if err != nil {
- fmt.Println(err.Error())
- e.Data["json"] = err.Error()
- e.ServeJSON()
- }
- stmt, err1 := db.Prepare(CreateApplyLeaveTable())
- if err1 != nil {
- e.Data["json"] = err.Error()
- e.ServeJSON()
- }
- defer stmt.Close()
- _, err = stmt.Exec()
- if err != nil {
- e.Data["json"] = err.Error()
- e.ServeJSON()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement