aboutsummaryrefslogtreecommitdiff
path: root/mysql/custom/test.hxx
blob: 82cc59d4019720abc42fa48cdc1784c15ac8fccc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// file      : mysql/custom/test.hxx
// license   : GNU GPL v2; see accompanying LICENSE file

#ifndef TEST_HXX
#define TEST_HXX

#include <vector>

#include <odb/core.hxx>

// Map GEOMETRY MySQL type to the point C++ struct. The other half
// of this mapping is in traits.hxx (value_traits<point, id_string>).
//
#pragma db map type("GEOMETRY")        \
               as("VARCHAR(256)")      \
               to("ST_GeomFromText((?))") \
               from("ST_AsText((?))")

#pragma db value type("GEOMETRY")
struct point
{
  point () {}
  point (double x_, double y_): x (x_), y (y_) {}

  double x;
  double y;
};

inline bool
operator== (const point& a, const point& b)
{
  return a.x == b.x && a.y == b.y;
}

#pragma db object
struct object
{
  object () {}
  object (unsigned long id_) : id (id_) {}

  #pragma db id
  unsigned long id;

  point p;
  std::vector<point> pv;

  bool
  operator== (const object& y) const
  {
    return id == y.id && p == y.p && pv == y.pv;
  }
};

#endif // TEST_HXX