Skip to content

Commit

Permalink
Fix small oversights
Browse files Browse the repository at this point in the history
Fix incomplete instances in QueryBuilderSpec with primaryKeyConditionForId
Fix pk-columns in SchemaCompilerSpec to be unique and non-nullable for completeness
  • Loading branch information
MonaMayrhofer committed Mar 18, 2024
1 parent 3d2aa44 commit dbdd70d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Test/QueryBuilderSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type instance PrimaryKey "taggings" = UUID
instance Table Tagging where
columnNames = ["id", "post_id", "tag_id"]
primaryKeyColumnNames = ["id"]
primaryKeyConditionForId (Id id) = [("id", toField id)]

data CompositeTagging = CompositeTagging
{ postId :: UUID
Expand Down Expand Up @@ -103,6 +104,7 @@ type instance PrimaryKey "users" = UUID
instance Table User where
columnNames = ["id", "name"]
primaryKeyColumnNames = ["id"]
primaryKeyConditionForId (Id id) = [("id", toField id)]

data FavoriteTitle = FavoriteTitle
{
Expand Down
10 changes: 5 additions & 5 deletions Test/SchemaCompilerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ tests = do
it "should compile CanUpdate instance with an array type with an explicit cast" do
let statement = StatementCreateTable $ CreateTable {
name = "users",
columns = [ Column "id" PUUID Nothing False True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing],
columns = [ Column "id" PUUID Nothing True True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing],
primaryKeyConstraint = PrimaryKeyConstraint ["id"],
constraints = []
, unlogged = False
Expand All @@ -164,7 +164,7 @@ tests = do
let statement = StatementCreateTable CreateTable
{ name = "users"
, columns =
[ Column "id" PUUID Nothing False True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing
[ Column "id" PUUID Nothing True True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing
, Column {name = "electricity_unit_price", columnType = PDouble, defaultValue = Just (TypeCastExpression (DoubleExpression 0.17) PDouble), notNull = True, isUnique = False, generator = Nothing}
]
, primaryKeyConstraint = PrimaryKeyConstraint ["id"]
Expand Down Expand Up @@ -234,7 +234,7 @@ tests = do
let statement = StatementCreateTable CreateTable
{ name = "users"
, columns =
[ Column "id" PUUID Nothing False True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing
[ Column "id" PUUID Nothing True True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing
, Column {name = "electricity_unit_price", columnType = PDouble, defaultValue = Just (IntExpression 0), notNull = True, isUnique = False, generator = Nothing}
]
, primaryKeyConstraint = PrimaryKeyConstraint ["id"]
Expand Down Expand Up @@ -304,7 +304,7 @@ tests = do
let statement = StatementCreateTable CreateTable
{ name = "users"
, columns =
[ Column "id" PUUID Nothing False True Nothing
[ Column "id" PUUID Nothing True True Nothing
, Column {name = "ts", columnType = PTSVector, defaultValue = Nothing, notNull = True, isUnique = False, generator = Just (ColumnGenerator { generate = VarExpression "someResult", stored = False }) }
]
, primaryKeyConstraint = PrimaryKeyConstraint ["id"]
Expand Down Expand Up @@ -584,7 +584,7 @@ tests = do
it "should compile FilterPrimaryKey instance when primary key is called id" do
let statement = StatementCreateTable $ CreateTable {
name = "things",
columns = [ Column "id" PUUID Nothing False False Nothing ],
columns = [ Column "id" PUUID Nothing True True Nothing ],
primaryKeyConstraint = PrimaryKeyConstraint ["id"],
constraints = [],
unlogged = False
Expand Down

0 comments on commit dbdd70d

Please sign in to comment.