Skip to content

Commit e61d222

Browse files
authored
Update docs, add runBeam* functions (#207)
1 parent 0de1e98 commit e61d222

30 files changed

+110
-101
lines changed

beam-postgres/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.3.1.0
2+
3+
Add `runBeamPostgres` and `runBeamPostgresDebug` functions.
4+
15
# 0.3.0.0
26

37
Initial hackage beam-postgres

beam-postgres/Database/Beam/Postgres/Connection.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ module Database.Beam.Postgres.Connection
1414
( PgRowReadError(..), PgError(..)
1515
, Pg(..), PgF(..)
1616

17+
, runBeamPostgres, runBeamPostgresDebug
18+
1719
, pgRenderSyntax, runPgRowReader, getFields
1820

1921
, withPgDebug
@@ -300,11 +302,16 @@ newtype Pg a = Pg { runPg :: F PgF a }
300302
instance MonadIO Pg where
301303
liftIO x = liftF (PgLiftIO x id)
302304

305+
runBeamPostgresDebug :: (String -> IO ()) -> Pg.Connection -> Pg a -> IO a
306+
runBeamPostgresDebug dbg conn action =
307+
withPgDebug dbg conn action >>= either throwIO pure
308+
309+
runBeamPostgres :: Pg.Connection -> Pg a -> IO a
310+
runBeamPostgres = runBeamPostgresDebug (\_ -> pure ())
311+
303312
instance MonadBeam PgCommandSyntax Postgres Pg.Connection Pg where
304-
withDatabase conn action =
305-
withPgDebug (\_ -> pure ()) conn action >>= either throwIO pure
306-
withDatabaseDebug dbg conn action =
307-
withPgDebug dbg conn action >>= either throwIO pure
313+
withDatabase = runBeamPostgres
314+
withDatabaseDebug = runBeamPostgresDebug
308315

309316
runReturningMany cmd consume =
310317
liftF (PgRunReturning cmd consume id)

beam-postgres/beam-docs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
CHINOOK_POSTGRES_URL="https://raw.githubusercontent.com/lerocha/chinook-database/master/ChinookDatabase/DataSources/Chinook_PostgreSql.sql"
6-
EXPECTED_SHA256="013d267b57b31193adad64412ee4d0800807b39b4006028ce7fb958e0667a7e0"
6+
EXPECTED_SHA256="6945d59e3bca94591e2a96451b9bd69084b026f7fb7dbda3d15d06114ffb34c4"
77

88
PGCONNSTR=$1
99
PGDB=$2

beam-postgres/beam-postgres.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: beam-postgres
2-
version: 0.3.0.0
2+
version: 0.3.1.0
33
synopsis: Connection layer between beam and postgres
44
description: Beam driver for <https://www.postgresql.org/ PostgreSQL>, an advanced open-source RDBMS
55
homepage: http://tathougies.github.io/beam/user-guide/backends/beam-postgres

beam-sqlite/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.3.1.0
2+
3+
Add `runBeamSqlite` and `runBeamSqliteDebug` functions
4+
15
# 0.3.0.0
26

37
* Re-introduce backend parameter to `Database` class

beam-sqlite/Database/Beam/Sqlite/Connection.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ module Database.Beam.Sqlite.Connection
77
( Sqlite(..), SqliteM(..)
88
, sqliteUriSyntax
99

10+
, runBeamSqlite, runBeamSqliteDebug
11+
1012
-- * Emulated @INSERT RETURNING@ support
1113
, SqliteInsertReturning
1214
, insertReturning, runInsertReturningList
13-
, ) where
15+
) where
1416

1517
import Database.Beam.Backend
1618
import Database.Beam.Backend.SQL
@@ -182,9 +184,15 @@ sqliteUriSyntax =
182184
hdl <- open sqliteName
183185
pure (hdl, close hdl))
184186

187+
runBeamSqliteDebug :: (String -> IO ()) -> Connection -> SqliteM a -> IO a
188+
runBeamSqliteDebug debugStmt conn x = runReaderT (runSqliteM x) (debugStmt, conn)
189+
190+
runBeamSqlite :: Connection -> SqliteM a -> IO a
191+
runBeamSqlite = runBeamSqliteDebug (\_ -> pure ())
192+
185193
instance MonadBeam SqliteCommandSyntax Sqlite Connection SqliteM where
186-
withDatabase = withDatabaseDebug (\_ -> pure ())
187-
withDatabaseDebug printStmt conn x = runReaderT (runSqliteM x) (printStmt, conn)
194+
withDatabase = runBeamSqlite
195+
withDatabaseDebug = runBeamSqliteDebug
188196

189197
runNoReturn (SqliteCommandSyntax (SqliteSyntax cmd vals)) =
190198
SqliteM $ do

beam-sqlite/beam-docs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44

55
SQLITE_DB=$1
66
CHINOOK_SQLITE_URL="https://raw.githubusercontent.com/lerocha/chinook-database/master/ChinookDatabase/DataSources/Chinook_Sqlite.sql"
7-
EXPECTED_SHA256="40215158e0dc3443d16565e3ae96c2f5d640ff00a92de3910568dc34fa086a82"
7+
EXPECTED_SHA256="b2e430ec8cb389509d25ec5bda2f958bbf6f0ca42e276fa5eb3de45eb816a460"
88

99
print_open_statement() {
1010
echo "chinook <- open \"chinook.db\""

beam-sqlite/beam-sqlite.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
name: beam-sqlite
3-
version: 0.3.0.0
3+
version: 0.3.1.0
44
synopsis: Beam driver for SQLite
55
description: Beam driver for the <https://sqlite.org/ SQLite> embedded database.
66
See <http://tathougies.github.io/beam/user-guide/backends/beam-sqlite/ here>

docs/beam-docs-library.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@ download () {
2929
DIR=$(dirname $TMP_FILE)
3030
mkdir -p $DIR
3131

32-
if [ -z $CONV ]; then
33-
curl $URL | sed -e 's/\r$//' > $TMP_FILE
34-
else
35-
curl $URL | $CONV | sed -e 's/\r$//' > $TMP_FILE
36-
fi
32+
curl $URL > $TMP_FILE
3733

3834
ACTUAL_SUM=$(sha256 $TMP_FILE)
3935
if [ "$ACTUAL_SUM" != "$EXPECTED_SHA256" ]; then
4036
status "Sum mismatch, got $ACTUAL_SUM, expected $EXPECTED_SHA256"
4137
exit 1
4238
else
43-
mv $TMP_FILE $CACHED_FILE
39+
if [ -z $CONV ]; then
40+
cat $TMP_FILE | sed -e 's/\r$//' > $CACHED_FILE
41+
else
42+
cat $TMP_FILE | bash -c "$CONV" | sed -e 's/\r$//' > $CACHED_FILE
43+
fi
44+
rm $TMP_FILE
4445
fi
4546

4647
status "Finished downloading"

docs/beam-templates/chinook.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ main =
3434
stmts <- newIORef id
3535

3636
let onStmt s = modifyIORef stmts (. (s:))
37+
38+
record :: BEAM_BACKEND_MONAD a -> IO a
3739
record = withDatabaseDebug onStmt chinook
3840

3941
handle (\BeamDone -> pure ()) $

0 commit comments

Comments
 (0)