From 90060f21374e1f2b0c2193f9d40f078634ac4b67 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Tue, 14 Jun 2011 10:00:38 +0200 Subject: Add PostgreSQL schema generation implementation --- odb/relational/pgsql/schema.cxx | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 odb/relational/pgsql/schema.cxx diff --git a/odb/relational/pgsql/schema.cxx b/odb/relational/pgsql/schema.cxx new file mode 100644 index 0000000..c3a2a3d --- /dev/null +++ b/odb/relational/pgsql/schema.cxx @@ -0,0 +1,55 @@ +// file : odb/relational/pgsql/schema.cxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v3; see accompanying LICENSE file + +#include + +#include +#include + +namespace relational +{ + namespace pgsql + { + namespace schema + { + namespace relational = relational::schema; + + // + // Create. + // + + struct object_columns: relational::object_columns + { + object_columns (base const& x): base (x) {} + + virtual void + type (semantics::data_member& m) + { + if (m.count ("auto")) + { + // @@ Is this even vaguely correct? + // + + const sql_type& t (pgsql::context::current ().column_sql_type (m)); + + if (t.type == sql_type::INTEGER) + os << " SERIAL"; + else if (t.type == sql_type::BIGINT) + os << " BIGSERIAL"; + else + { + cerr << m.file () << ":" << m.line () << ":" << m.column () + << ": error: auto increment columns must be either of " + << "PostgreSQL type INTEGER or BIGINT" << endl; + + throw generation_failed (); + } + } + } + }; + entry object_columns_; + } + } +} -- cgit v1.1