Skip to content

Commit

Permalink
Make query builder use Table API to access the table name
Browse files Browse the repository at this point in the history
This allows for easier building custom data records that use an existing table
  • Loading branch information
mpscholten committed Feb 8, 2022
1 parent 02441a6 commit 92f0679
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 54 deletions.
3 changes: 2 additions & 1 deletion IHP/ModelSupport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import Data.Dynamic
import Data.Scientific
import GHC.Stack
import qualified Numeric
import qualified Data.Text.Encoding as Text

-- | Provides the db connection and some IHP-specific db configuration
data ModelContext = ModelContext
Expand Down Expand Up @@ -533,7 +534,7 @@ class
-- "users"
--
tableNameByteString :: ByteString
tableNameByteString = symbolToByteString @(GetTableName record)
tableNameByteString = Text.encodeUtf8 (tableName @record)
{-# INLINE tableNameByteString #-}

-- | Returns the list of column names for a given model
Expand Down
6 changes: 4 additions & 2 deletions IHP/Pagination/ControllerFunctions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import IHP.QueryBuilder
( HasQueryBuilder, filterWhereILike, limit, offset )
import IHP.Fetch (fetchCount)

import IHP.ModelSupport (GetModelByTableName, sqlQuery, sqlQueryScalar)
import IHP.ModelSupport (GetModelByTableName, sqlQuery, sqlQueryScalar, Table)

import Database.PostgreSQL.Simple.ToField (toField, Action)
import Database.PostgreSQL.Simple.Types (Query(Query))
Expand Down Expand Up @@ -131,7 +131,9 @@ filterList :: forall name table model queryBuilderProvider joinRegister .
, HasField name model Text
, model ~ GetModelByTableName table
, KnownSymbol table
, HasQueryBuilder queryBuilderProvider joinRegister) =>
, HasQueryBuilder queryBuilderProvider joinRegister
, Table model
) =>
Proxy name
-> queryBuilderProvider table
-> queryBuilderProvider table
Expand Down
Loading

0 comments on commit 92f0679

Please sign in to comment.