-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Backend for the persistent library using postgresql.
--   
--   Based on the postgresql-simple package
@package persistent-postgresql
@version 2.9.1


-- | A postgresql backend for persistent.
module Database.Persist.Postgresql

-- | Create a PostgreSQL connection pool and run the given action. The pool
--   is properly released after the action finishes using it. Note that you
--   should not use the given <a>ConnectionPool</a> outside the action
--   since it may already have been released.
withPostgresqlPool :: (MonadLogger m, MonadUnliftIO m, IsSqlBackend backend) => ConnectionString -> Int -> (Pool backend -> m a) -> m a

-- | Same as <tt>withPostgresPool</tt>, but takes a callback for obtaining
--   the server version (to work around an Amazon Redshift bug).
withPostgresqlPoolWithVersion :: (MonadUnliftIO m, MonadLogger m, IsSqlBackend backend) => (Connection -> IO (Maybe Double)) -> ConnectionString -> Int -> (Pool backend -> m a) -> m a

-- | Same as <a>withPostgresqlPool</a>, but instead of opening a pool of
--   connections, only one connection is opened.
withPostgresqlConn :: (MonadUnliftIO m, MonadLogger m, IsSqlBackend backend) => ConnectionString -> (backend -> m a) -> m a

-- | Same as <a>withPostgresqlConn</a>, but takes a callback for obtaining
--   the server version (to work around an Amazon Redshift bug).
withPostgresqlConnWithVersion :: (MonadUnliftIO m, MonadLogger m, IsSqlBackend backend) => (Connection -> IO (Maybe Double)) -> ConnectionString -> (backend -> m a) -> m a

-- | Create a PostgreSQL connection pool. Note that it's your
--   responsibility to properly close the connection pool when unneeded.
--   Use <a>withPostgresqlPool</a> for an automatic resource control.
createPostgresqlPool :: (MonadUnliftIO m, MonadLogger m, IsSqlBackend backend) => ConnectionString -> Int -> m (Pool backend)

-- | Same as <a>createPostgresqlPool</a>, but additionally takes a callback
--   function for some connection-specific tweaking to be performed after
--   connection creation. This could be used, for example, to change the
--   schema. For more information, see:
--   
--   
--   <a>https://groups.google.com/d/msg/yesodweb/qUXrEN_swEo/O0pFwqwQIdcJ</a>
createPostgresqlPoolModified :: (MonadUnliftIO m, MonadLogger m, IsSqlBackend backend) => (Connection -> IO ()) -> ConnectionString -> Int -> m (Pool backend)

-- | Same as other similarly-named functions in this module, but takes
--   callbacks for obtaining the server version (to work around an Amazon
--   Redshift bug) and connection-specific tweaking (to change the schema).
createPostgresqlPoolModifiedWithVersion :: (MonadUnliftIO m, MonadLogger m, IsSqlBackend backend) => (Connection -> IO (Maybe Double)) -> (Connection -> IO ()) -> ConnectionString -> Int -> m (Pool backend)

-- | A <tt>libpq</tt> connection string. A simple example of connection
--   string would be <tt>"host=localhost port=5432 user=test dbname=test
--   password=test"</tt>. Please read libpq's documentation at
--   <a>https://www.postgresql.org/docs/current/static/libpq-connect.html</a>
--   for more details on how to create such strings.
type ConnectionString = ByteString

-- | Information required to connect to a PostgreSQL database using
--   <tt>persistent</tt>'s generic facilities. These values are the same
--   that are given to <a>withPostgresqlPool</a>.
data PostgresConf
PostgresConf :: ConnectionString -> Int -> PostgresConf

-- | The connection string.
[pgConnStr] :: PostgresConf -> ConnectionString

-- | How many connections should be held in the connection pool.
[pgPoolSize] :: PostgresConf -> Int

-- | Generate a <a>SqlBackend</a> from a <a>Connection</a>.
openSimpleConn :: IsSqlBackend backend => LogFunc -> Connection -> IO backend

-- | Generate a <a>SqlBackend</a> from a <a>Connection</a>, but takes a
--   callback for obtaining the server version.
openSimpleConnWithVersion :: IsSqlBackend backend => (Connection -> IO (Maybe Double)) -> LogFunc -> Connection -> IO backend

-- | Get the SQL string for the table that a PeristEntity represents.
--   Useful for raw SQL queries.
tableName :: PersistEntity record => record -> Text

-- | Get the SQL string for the field that an EntityField represents.
--   Useful for raw SQL queries.
fieldName :: PersistEntity record => EntityField record typ -> Text

-- | Mock a migration even when the database is not present. This function
--   performs the same functionality of <a>printMigration</a> with the
--   difference that an actual database is not needed.
mockMigration :: Migration -> IO ()

-- | Enable a Postgres extension. See
--   <a>https://www.postgresql.org/docs/current/static/contrib.html</a> for
--   a list.
migrateEnableExtension :: Text -> Migration
instance Data.Data.Data Database.Persist.Postgresql.PostgresConf
instance GHC.Read.Read Database.Persist.Postgresql.PostgresConf
instance GHC.Show.Show Database.Persist.Postgresql.PostgresConf
instance GHC.Classes.Ord Database.Persist.Postgresql.Unknown
instance GHC.Read.Read Database.Persist.Postgresql.Unknown
instance GHC.Show.Show Database.Persist.Postgresql.Unknown
instance GHC.Classes.Eq Database.Persist.Postgresql.Unknown
instance Data.Aeson.Types.FromJSON.FromJSON Database.Persist.Postgresql.PostgresConf
instance Database.Persist.Class.PersistConfig.PersistConfig Database.Persist.Postgresql.PostgresConf
instance Database.PostgreSQL.Simple.ToField.ToField Database.Persist.Postgresql.P
instance Database.PostgreSQL.Simple.FromField.FromField Database.Persist.Postgresql.Unknown
instance Database.PostgreSQL.Simple.ToField.ToField Database.Persist.Postgresql.Unknown
instance GHC.Show.Show Database.Persist.Postgresql.PostgresServerVersionError
instance GHC.Exception.Type.Exception Database.Persist.Postgresql.PostgresServerVersionError


-- | Filter operators for JSON values added to PostgreSQL 9.4
module Database.Persist.Postgresql.JSON

-- | This operator checks inclusion of the JSON value on the right hand
--   side in the JSON value on the left hand side.
--   
--   <h3><b>Objects</b></h3>
--   
--   An empty Object matches any object
--   
--   <pre>
--   {}                @&gt; {} == True
--   {"a":1,"b":false} @&gt; {} == True
--   </pre>
--   
--   Any key-value will be matched top-level
--   
--   <pre>
--   {"a":1,"b":{"c":true"}} @&gt; {"a":1}         == True
--   {"a":1,"b":{"c":true"}} @&gt; {"b":1}         == False
--   {"a":1,"b":{"c":true"}} @&gt; {"b":{}}        == True
--   {"a":1,"b":{"c":true"}} @&gt; {"c":true}      == False
--   {"a":1,"b":{"c":true"}} @&gt; {"b":{c":true}} == True
--   </pre>
--   
--   <h3><b>Arrays</b></h3>
--   
--   An empty Array matches any array
--   
--   <pre>
--   []                    @&gt; [] == True
--   [1,2,"hi",false,null] @&gt; [] == True
--   </pre>
--   
--   Any array has to be a sub-set. Any object or array will also be
--   compared as being a subset of.
--   
--   <pre>
--   [1,2,"hi",false,null] @&gt; [1]                       == True
--   [1,2,"hi",false,null] @&gt; [null,"hi"]               == True
--   [1,2,"hi",false,null] @&gt; ["hi",true]               == False
--   [1,2,"hi",false,null] @&gt; ["hi",2,null,false,1]     == True
--   [1,2,"hi",false,null] @&gt; [1,2,"hi",false,null,{}]  == False
--   </pre>
--   
--   Arrays and objects inside arrays match the same way they'd be matched
--   as being on their own.
--   
--   <pre>
--   [1,"hi",[false,3],{"a":[null]}] @&gt; [{}]            == True
--   [1,"hi",[false,3],{"a":[null]}] @&gt; [{"a":[]}]      == True
--   [1,"hi",[false,3],{"a":[null]}] @&gt; [{"b":[null]}]  == False
--   [1,"hi",[false,3],{"a":[null]}] @&gt; [[]]            == True
--   [1,"hi",[false,3],{"a":[null]}] @&gt; [[3]]           == True
--   [1,"hi",[false,3],{"a":[null]}] @&gt; [[true,3]]      == False
--   </pre>
--   
--   A regular value has to be a member
--   
--   <pre>
--   [1,2,"hi",false,null] @&gt; 1      == True
--   [1,2,"hi",false,null] @&gt; 5      == False
--   [1,2,"hi",false,null] @&gt; "hi"   == True
--   [1,2,"hi",false,null] @&gt; false  == True
--   [1,2,"hi",false,null] @&gt; "2"    == False
--   </pre>
--   
--   An object will never match with an array
--   
--   <pre>
--   [1,2,"hi",[false,3],{"a":null}] @&gt; {}          == False
--   [1,2,"hi",[false,3],{"a":null}] @&gt; {"a":null}  == False
--   </pre>
--   
--   <h3><b>Other values</b></h3>
--   
--   For any other JSON values the `(@&gt;.)` operator functions like an
--   equivalence operator.
--   
--   <pre>
--   "hello" @&gt; "hello"     == True
--   "hello" @&gt; "Hello"     == False
--   "hello" @&gt; "h"         == False
--   "hello" @&gt; {"hello":1} == False
--   "hello" @&gt; ["hello"]   == False
--   
--   5       @&gt; 5       == True
--   5       @&gt; 5.00    == True
--   5       @&gt; 1       == False
--   5       @&gt; 7       == False
--   12345   @&gt; 1234    == False
--   12345   @&gt; 2345    == False
--   12345   @&gt; "12345" == False
--   12345   @&gt; [1,2,3,4,5] == False
--   
--   true    @&gt; true    == True
--   true    @&gt; false   == False
--   false   @&gt; true    == False
--   true    @&gt; "true"  == False
--   
--   null    @&gt; null    == True
--   null    @&gt; 23      == False
--   null    @&gt; "null"  == False
--   null    @&gt; {}      == False
--   </pre>
(@>.) :: EntityField record Value -> Value -> Filter record
infix 4 @>.

-- | Same as <a>@&gt;.</a> except the inclusion check is reversed. i.e. is
--   the JSON value on the left hand side included in the JSON value of the
--   right hand side.
(<@.) :: EntityField record Value -> Value -> Filter record
infix 4 <@.

-- | A JSON value represented as a Haskell value.
data Value
instance Database.Persist.Class.PersistField.PersistField Data.Aeson.Types.Internal.Value
instance Database.Persist.Sql.Class.PersistFieldSql Data.Aeson.Types.Internal.Value
