@@ -36,208 +36,6 @@ import Yoga.Postgres.ClientOm
37import Yoga.Postgres.Schema (Table, PrimaryKey, AutoIncrement, Unique, Default, DefaultExpr, ForeignKey, References, PGUUID)
37import Yoga.Postgres.Schema (Table, PrimaryKey, AutoIncrement, Unique, Default, DefaultExpr, ForeignKey, References, PGUUID)
39−-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
41−-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
43−type UsersTable = Table "test_om_users"
44− ( id :: PrimaryKey (AutoIncrement Int)
46− , email :: Unique String
47− , active :: Default "true" Boolean
51−usersTable :: Proxy UsersTable
54−type SettingsTable = Table "test_om_settings"
55− ( key :: PrimaryKey String
59−settingsTable :: Proxy SettingsTable
62−type UuidTable = Table "test_om_uuid_things"
63− ( id :: PGUUID # PrimaryKey # DefaultExpr "gen_random_uuid()"
67−uuidTable :: Proxy UuidTable
70−type PostsTable = Table "test_om_posts"
71− ( id :: PrimaryKey (AutoIncrement Int)
74− , user_id :: ForeignKey "test_om_users" References "id" Int
77−postsTable :: Proxy PostsTable
80−type CommentsTable = Table "test_om_comments"
81− ( id :: PrimaryKey (AutoIncrement Int)
83− , user_id :: ForeignKey "test_om_users" References "id" Int
86−commentsTable :: Proxy CommentsTable
89−-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
91−-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
93−testConnection :: Aff PG.Connection
96− { host: PG.PostgresHost "localhost"
97− , port: PG.PostgresPort 5433
98− , database: PG.PostgresDatabase "test_playground"
99− , username: PG.PostgresUsername "postgres"
100− , password: PG.PostgresPassword "postgres"
105− . Om.Om { postgresConnection :: PG.Connection } (parseError :: MultipleErrors) a
108−run om conn = Om.runOm { postgresConnection: conn }
109− { exception: \e -> throwError e
110− , parseError: \errs -> throwError (error ("Parse error: " <> show errs))
116− . Om.Om { postgresConnection :: PG.Connection } () a
119−runNoErr om conn = Om.runOm { postgresConnection: conn }
120− { exception: \e -> throwError e }
123−withUsersTable :: (PG.Connection -> Aff Unit) -> Aff Unit
124−withUsersTable test = do
125− conn <- testConnection
126− _ <- PG.executeSimple createDDL conn
128− _ <- PG.executeSimple dropDDL conn
131− dropDDL = PG.SQL "DROP TABLE IF EXISTS test_om_users CASCADE"
133− """DROP TABLE IF EXISTS test_om_users CASCADE;
134− CREATE TABLE test_om_users (
135− id SERIAL PRIMARY KEY,
137− email TEXT UNIQUE NOT NULL,
138− active BOOLEAN DEFAULT true NOT NULL,
142−withSettingsTable :: (PG.Connection -> Aff Unit) -> Aff Unit
143−withSettingsTable test = do
144− conn <- testConnection
145− _ <- PG.executeSimple createDDL conn
147− _ <- PG.executeSimple dropDDL conn
150− dropDDL = PG.SQL "DROP TABLE IF EXISTS test_om_settings CASCADE"
152− """DROP TABLE IF EXISTS test_om_settings CASCADE;
153− CREATE TABLE test_om_settings (
154− key TEXT PRIMARY KEY,
158−withUuidTable :: (PG.Connection -> Aff Unit) -> Aff Unit
159−withUuidTable test = do
160− conn <- testConnection
161− _ <- PG.executeSimple createDDL conn
163− _ <- PG.executeSimple dropDDL conn
166− dropDDL = PG.SQL "DROP TABLE IF EXISTS test_om_uuid_things CASCADE"
168− """DROP TABLE IF EXISTS test_om_uuid_things CASCADE;
169− CREATE TABLE test_om_uuid_things (
170− id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
174−withPostsTable :: (PG.Connection -> Aff Unit) -> Aff Unit
175−withPostsTable test = do
176− conn <- testConnection
177− _ <- PG.executeSimple createDDL conn
179− _ <- PG.executeSimple (PG.SQL "DROP TABLE IF EXISTS test_om_posts CASCADE") conn
180− _ <- PG.executeSimple (PG.SQL "DROP TABLE IF EXISTS test_om_users CASCADE") conn
184− """DROP TABLE IF EXISTS test_om_posts CASCADE;
185− DROP TABLE IF EXISTS test_om_users CASCADE;
186− CREATE TABLE test_om_users (
187− id SERIAL PRIMARY KEY,
189− email TEXT UNIQUE NOT NULL,
190− active BOOLEAN DEFAULT true NOT NULL,
193− CREATE TABLE test_om_posts (
194− id SERIAL PRIMARY KEY,
195− title TEXT NOT NULL,
197− user_id INTEGER NOT NULL REFERENCES test_om_users(id)
200−withPostsAndCommentsTable :: (PG.Connection -> Aff Unit) -> Aff Unit
201−withPostsAndCommentsTable test = do
202− conn <- testConnection
203− _ <- PG.executeSimple createDDL conn
205− _ <- PG.executeSimple (PG.SQL "DROP TABLE IF EXISTS test_om_comments CASCADE") conn
206− _ <- PG.executeSimple (PG.SQL "DROP TABLE IF EXISTS test_om_posts CASCADE") conn
207− _ <- PG.executeSimple (PG.SQL "DROP TABLE IF EXISTS test_om_users CASCADE") conn
211− """DROP TABLE IF EXISTS test_om_comments CASCADE;
212− DROP TABLE IF EXISTS test_om_posts CASCADE;
213− DROP TABLE IF EXISTS test_om_users CASCADE;
214− CREATE TABLE test_om_users (
215− id SERIAL PRIMARY KEY,
217− email TEXT UNIQUE NOT NULL,
218− active BOOLEAN DEFAULT true NOT NULL,
221− CREATE TABLE test_om_posts (
222− id SERIAL PRIMARY KEY,
223− title TEXT NOT NULL,
225− user_id INTEGER NOT NULL REFERENCES test_om_users(id)
227− CREATE TABLE test_om_comments (
228− id SERIAL PRIMARY KEY,
230− user_id INTEGER NOT NULL REFERENCES test_om_users(id)
233−shouldBeJust :: forall a. Maybe a -> Aff a
234−shouldBeJust (Just a) = pure a
235−shouldBeJust Nothing = throwError $ error "Expected Just but got Nothing"
237−-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
239−-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
241spec :: Spec Unit
39spec :: Spec Unit
242spec = describe "ClientOm" do
40spec = describe "ClientOm" do
@@ -789,3 +587,201 @@ spec = describe "ClientOm" do
789 r3.label `shouldEqual` "first"
587 r3.label `shouldEqual` "first"
790 yes <- conn # runNoErr do uuidTable # exists row.id
588 yes <- conn # runNoErr do uuidTable # exists row.id
791 yes `shouldEqual` true
589 yes `shouldEqual` true
591+-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
593+-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
595+type UsersTable = Table "test_om_users"
596+ ( id :: PrimaryKey (AutoIncrement Int)
598+ , email :: Unique String
599+ , active :: Default "true" Boolean
603+usersTable :: Proxy UsersTable
606+type SettingsTable = Table "test_om_settings"
607+ ( key :: PrimaryKey String
611+settingsTable :: Proxy SettingsTable
612+settingsTable = Proxy
614+type UuidTable = Table "test_om_uuid_things"
615+ ( id :: PGUUID # PrimaryKey # DefaultExpr "gen_random_uuid()"
619+uuidTable :: Proxy UuidTable
622+type PostsTable = Table "test_om_posts"
623+ ( id :: PrimaryKey (AutoIncrement Int)
626+ , user_id :: ForeignKey "test_om_users" References "id" Int
629+postsTable :: Proxy PostsTable
632+type CommentsTable = Table "test_om_comments"
633+ ( id :: PrimaryKey (AutoIncrement Int)
635+ , user_id :: ForeignKey "test_om_users" References "id" Int
638+commentsTable :: Proxy CommentsTable
639+commentsTable = Proxy
641+-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
643+-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
645+testConnection :: Aff PG.Connection
648+ { host: PG.PostgresHost "localhost"
649+ , port: PG.PostgresPort 5433
650+ , database: PG.PostgresDatabase "test_playground"
651+ , username: PG.PostgresUsername "postgres"
652+ , password: PG.PostgresPassword "postgres"
657+ . Om.Om { postgresConnection :: PG.Connection } (parseError :: MultipleErrors) a
660+run om conn = Om.runOm { postgresConnection: conn }
661+ { exception: \e -> throwError e
662+ , parseError: \errs -> throwError (error ("Parse error: " <> show errs))
668+ . Om.Om { postgresConnection :: PG.Connection } () a
671+runNoErr om conn = Om.runOm { postgresConnection: conn }
672+ { exception: \e -> throwError e }
675+withUsersTable :: (PG.Connection -> Aff Unit) -> Aff Unit
676+withUsersTable test = do
677+ conn <- testConnection
678+ _ <- PG.executeSimple createDDL conn
680+ _ <- PG.executeSimple dropDDL conn
683+ dropDDL = PG.SQL "DROP TABLE IF EXISTS test_om_users CASCADE"
685+ """DROP TABLE IF EXISTS test_om_users CASCADE;
686+ CREATE TABLE test_om_users (
687+ id SERIAL PRIMARY KEY,
689+ email TEXT UNIQUE NOT NULL,
690+ active BOOLEAN DEFAULT true NOT NULL,
694+withSettingsTable :: (PG.Connection -> Aff Unit) -> Aff Unit
695+withSettingsTable test = do
696+ conn <- testConnection
697+ _ <- PG.executeSimple createDDL conn
699+ _ <- PG.executeSimple dropDDL conn
702+ dropDDL = PG.SQL "DROP TABLE IF EXISTS test_om_settings CASCADE"
704+ """DROP TABLE IF EXISTS test_om_settings CASCADE;
705+ CREATE TABLE test_om_settings (
706+ key TEXT PRIMARY KEY,
710+withUuidTable :: (PG.Connection -> Aff Unit) -> Aff Unit
711+withUuidTable test = do
712+ conn <- testConnection
713+ _ <- PG.executeSimple createDDL conn
715+ _ <- PG.executeSimple dropDDL conn
718+ dropDDL = PG.SQL "DROP TABLE IF EXISTS test_om_uuid_things CASCADE"
720+ """DROP TABLE IF EXISTS test_om_uuid_things CASCADE;
721+ CREATE TABLE test_om_uuid_things (
722+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
726+withPostsTable :: (PG.Connection -> Aff Unit) -> Aff Unit
727+withPostsTable test = do
728+ conn <- testConnection
729+ _ <- PG.executeSimple createDDL conn
731+ _ <- PG.executeSimple (PG.SQL "DROP TABLE IF EXISTS test_om_posts CASCADE") conn
732+ _ <- PG.executeSimple (PG.SQL "DROP TABLE IF EXISTS test_om_users CASCADE") conn
736+ """DROP TABLE IF EXISTS test_om_posts CASCADE;
737+ DROP TABLE IF EXISTS test_om_users CASCADE;
738+ CREATE TABLE test_om_users (
739+ id SERIAL PRIMARY KEY,
741+ email TEXT UNIQUE NOT NULL,
742+ active BOOLEAN DEFAULT true NOT NULL,
745+ CREATE TABLE test_om_posts (
746+ id SERIAL PRIMARY KEY,
747+ title TEXT NOT NULL,
749+ user_id INTEGER NOT NULL REFERENCES test_om_users(id)
752+withPostsAndCommentsTable :: (PG.Connection -> Aff Unit) -> Aff Unit
753+withPostsAndCommentsTable test = do
754+ conn <- testConnection
755+ _ <- PG.executeSimple createDDL conn
757+ _ <- PG.executeSimple (PG.SQL "DROP TABLE IF EXISTS test_om_comments CASCADE") conn
758+ _ <- PG.executeSimple (PG.SQL "DROP TABLE IF EXISTS test_om_posts CASCADE") conn
759+ _ <- PG.executeSimple (PG.SQL "DROP TABLE IF EXISTS test_om_users CASCADE") conn
763+ """DROP TABLE IF EXISTS test_om_comments CASCADE;
764+ DROP TABLE IF EXISTS test_om_posts CASCADE;
765+ DROP TABLE IF EXISTS test_om_users CASCADE;
766+ CREATE TABLE test_om_users (
767+ id SERIAL PRIMARY KEY,
769+ email TEXT UNIQUE NOT NULL,
770+ active BOOLEAN DEFAULT true NOT NULL,
773+ CREATE TABLE test_om_posts (
774+ id SERIAL PRIMARY KEY,
775+ title TEXT NOT NULL,
777+ user_id INTEGER NOT NULL REFERENCES test_om_users(id)
779+ CREATE TABLE test_om_comments (
780+ id SERIAL PRIMARY KEY,
782+ user_id INTEGER NOT NULL REFERENCES test_om_users(id)
785+shouldBeJust :: forall a. Maybe a -> Aff a
786+shouldBeJust (Just a) = pure a
787+shouldBeJust Nothing = throwError $ error "Expected Just but got Nothing"