Advertisement
Guest User

Untitled

a guest
Nov 28th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. func CreateApplyLeaveTable() string {
  2. applyLeaveTable := `CREATE TABLE apply_leave1 (
  3. leaveid serial PRIMARY KEY NOT NULL ,
  4. empid varchar(10) NOT NULL ,
  5. leavedays double precision NOT NULL DEFAULT 0 ,
  6. mdays double precision NOT NULL DEFAULT 0 ,
  7. leavetype varchar(20) NOT NULL DEFAULT '' ,
  8. daytype text NOT NULL '',
  9. leavefrom timestamp with time zone NOT NULL,
  10. leaveto timestamp with time zone NOT NULL,
  11. applieddate timestamp with time zone NOT NULL,
  12. leavestatus varchar(15) NOT NULL DEFAULT '' ,
  13. resultdate timestamp with time zone,
  14. certificatestatus bool NOT NULL DEFAULT FALSE
  15. certificate json NULL)`
  16. return applyLeaveTable
  17. }
  18. import(
  19. "database/sql"
  20. "fmt"
  21. _"github.com/lib/pq"
  22. )
  23. func (e *EmployeeController) Leave() {
  24.  
  25. conn := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable",
  26. "postgres", "root", "employee")
  27. log.Println("Creating a new connection: %v", conn)
  28.  
  29. db, err := sql.Open("postgres", conn)
  30. if err != nil {
  31. fmt.Println(err.Error())
  32. e.Data["json"] = err.Error()
  33. e.ServeJSON()
  34.  
  35. }
  36. stmt, err1 := db.Prepare(CreateApplyLeaveTable())
  37. if err1 != nil {
  38. e.Data["json"] = err.Error()
  39. e.ServeJSON()
  40. }
  41. defer stmt.Close()
  42. _, err = stmt.Exec()
  43. if err != nil {
  44. e.Data["json"] = err.Error()
  45. e.ServeJSON()
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement