Module

Control.Monad.Postgres.Cursor

Package
purescript-postgresql
Repository
cakekindel/purescript-postgresql

#Move Source

data Move

Constructors

#CursorT Source

newtype CursorT :: forall k. Type -> (k -> Type) -> k -> Typenewtype CursorT t m a

Constructors

Instances

#MonadCursor Source

class MonadCursor :: (Type -> Type) -> Type -> Constraintclass (MonadSession m) <= MonadCursor m t  where

A monad representing a handle to a server-side cursor

runPostgres {connectionString: "..."} do
  exec_ "create table foo (id int not null primary key);"
  exec_
    $ intercalate "\n "
      [ "insert into foo (id)"
      , "values"
      , intercalate ", "
          $ map (\n -> "(" <> show n <> ")")
          $ Array.range 1 100
      ]

  cursor @Int "foo_cursor" "select id from foo" do
    a <- fetchOne -- 1
    b <- fetchOne -- 2
    c <- fetchOne -- 3
    d <- fetch 10 -- 4..14
    e <- fetchAll -- 15..100
    pure unit

Members

  • fetch :: Int -> m (Array t)

    Fetch a specified number of rows from the cursor

  • fetchAll :: m (Array t)

    Fetch all remaining rows from the cursor

  • move :: Move -> m Int

    Change the cursor's position without fetching any data, returning the number of rows skipped.

Instances

#fetchOne Source

fetchOne :: forall m t. MonadCursor m t => m (Maybe t)

Fetch the next row from the cursor