main.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package main
  2. import (
  3. "context"
  4. "github.com/dolphindb/api-go/api"
  5. )
  6. func main() {
  7. host := "192.168.0.153:8848"
  8. // init client
  9. db, err := api.NewDolphinDBClient(context.TODO(), host, nil)
  10. if err != nil {
  11. // Handle exception
  12. panic(err)
  13. }
  14. // connect to server
  15. err = db.Connect()
  16. if err != nil {
  17. // Handle exception
  18. panic(err)
  19. }
  20. // init login request
  21. loginReq := &api.LoginRequest{
  22. UserID: "admin",
  23. Password: "123456",
  24. }
  25. // login dolphindb
  26. err = db.Login(loginReq)
  27. if err != nil {
  28. // Handle exception
  29. panic(err)
  30. }
  31. // init create database request
  32. dbReq := &api.DatabaseRequest{
  33. Directory: "dfs://account1",
  34. PartitionType: "VALUE",
  35. PartitionScheme: "1..1000", // 以project_id进行分区
  36. DBHandle: "example",
  37. }
  38. // create database
  39. dt, err := db.Database(dbReq)
  40. if err != nil {
  41. // Handle exception
  42. panic(err)
  43. }
  44. // init create partitioned table request
  45. createReq := &api.CreatePartitionedTableRequest{
  46. SrcTable: "sourceTable",
  47. PartitionedTableName: "tableName",
  48. PartitionColumns: []string{"project_id"},
  49. }
  50. // create partitioned table with database handler
  51. _, err = dt.CreatePartitionedTable(createReq)
  52. if err != nil {
  53. // Handle exception
  54. panic(err)
  55. }
  56. }