// file      : odb/pgsql/connection.ixx
// license   : GNU GPL v2; see accompanying LICENSE file

namespace odb
{
  namespace pgsql
  {
    inline database& connection::
    database ()
    {
      return static_cast<connection_factory&> (factory_).database ();
    }

    inline std::unique_ptr<transaction_impl> connection::
    begin ()
    {
      // Go through the virtual begin_() function instead of directly to allow
      // overriding.
      //
      return std::unique_ptr<transaction_impl> (
        static_cast<pgsql::transaction_impl*> (begin_ ().release ()));
    }

    template <typename T>
    inline prepared_query<T> connection::
    prepare_query (const char* n, const char* q)
    {
      return prepare_query<T> (n, query<T> (q));
    }

    template <typename T>
    inline prepared_query<T> connection::
    prepare_query (const char* n, const std::string& q)
    {
      return prepare_query<T> (n, query<T> (q));
    }

    template <typename T>
    inline prepared_query<T> connection::
    prepare_query (const char* n, const pgsql::query_base& q)
    {
      return query_<T, id_pgsql>::call (*this, n, q);
    }

    template <typename T>
    inline prepared_query<T> connection::
    prepare_query (const char* n, const odb::query_base& q)
    {
      // Translate to native query.
      //
      return prepare_query<T> (n, pgsql::query_base (q));
    }
  }
}
