diff options
author | Constantin Michael <constantin@codesynthesis.com> | 2011-06-14 10:00:38 +0200 |
---|---|---|
committer | Constantin Michael <constantin@codesynthesis.com> | 2011-07-05 14:43:38 +0200 |
commit | 90060f21374e1f2b0c2193f9d40f078634ac4b67 (patch) | |
tree | dcc9cc0dd735dcc54ea0f6724f99358f0db38751 | |
parent | b78b1510cdcd82b560cabda8c082aff8f0d3cc2d (diff) |
Add PostgreSQL schema generation implementation
-rw-r--r-- | odb/relational/pgsql/schema.cxx | 55 |
1 files changed, 55 insertions, 0 deletions
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 <constantin@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v3; see accompanying LICENSE file + +#include <odb/relational/schema.hxx> + +#include <odb/relational/pgsql/common.hxx> +#include <odb/relational/pgsql/context.hxx> + +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> object_columns_; + } + } +} |