> {-# LANGUAGE OverloadedStrings #-} > module Database.HsSqlPpp.Tests.Parsing.Schemas (schemas) where > import qualified Data.Text as T > import Database.HsSqlPpp.Syntax > import Database.HsSqlPpp.Tests.Parsing.Utils > import Database.HsSqlPpp.Tests.TestTypes > schemas :: Item > schemas = > Group "schema" [ > Group "ddl - schemas" [ > s "create schema test;" > [CreateSchema ea > (name "test") > Nothing] > ,s "create schema test authorization owner;" > [CreateSchema ea > (name "test") > (Just $ name "owner") > ] > ,Group "drop schema" [ > s "drop schema test;" > [DropSomething ea Schema Require [name "test"] Restrict] > ,s "drop schema if exists test restrict;" > [DropSomething ea Schema IfExists [name "test"] Restrict] > ,s "drop schema test cascade;" > [DropSomething ea Schema Require [name "test"] Cascade] > ] > ,Group "alter schema" [ > s "alter schema test rename to test2;" > [AlterSchema ea (name "test") $ AlterSchemaName ea (name "test2")] > ,s "alter schema test owner to new_owner;" > [AlterSchema ea (name "test") $ AlterSchemaOwner ea (name "new_owner")] > ] > ] > ,Group "ddl - schema-explicit tables" [ > s "create table s.test (\n\ > \ fielda text,\n\ > \ fieldb int\n\ > \);" > [CreateTable ea > (nameWithSchema "s" "test") > [att "fielda" "text" > ,att "fieldb" "int" > ] > [] > Nothing > NoReplace []] > ,s "alter table s.a rename to b;" > [AlterTable ea (nameWithSchema "s" "a") $ RenameTable ea (name "b")] > ,s "drop table s.t;" > [DropSomething ea Table Require [nameWithSchema "s" "t"] Restrict] > ] > ,Group "ddl - schema-explicit views" [ > s "create view s1.v1 as\n\ > \select a,b from s2.t;" > [CreateView ea > (nameWithSchema "s1" "v1") Nothing > (makeSelect > {selSelectList = sl [si $ ei "a" > ,si $ ei "b"] > ,selTref = [trefWithSchema "s2" "t"]})] > ,s "alter view s1.v1 as\n\ > \select a,b from s2.t;" > [AlterView ea > (nameWithSchema "s1" "v1") Nothing > (makeSelect > {selSelectList = sl [si $ ei "a" > ,si $ ei "b"] > ,selTref = [trefWithSchema "s2" "t"]})] > ,s "drop view s.v;" > [DropSomething ea View Require [nameWithSchema "s" "v"] Restrict] > ] > ,Group "dml - schemas" [ > q "select a from s.t" stbl{selTref = [trefWithSchema "s" "t"]} > ,q "select a from s1.t1 natural inner join t2" > stbl {selTref = [naturalInnerJoin (trefWithSchema "s1" "t1") (tref "t2") ]} > ] > ] > where > s = ParseStmts defaultParseFlags > stbl = makeSelect > {selSelectList = sl [si $ ei "a"] > ,selTref = []} > q = ParseQueryExpr defaultParseFlags > nameWithSchema sc n = Name ea $ [Nmc $ T.unpack sc, Nmc $ T.unpack n] > trefWithSchema sc t = Tref ea (nameWithSchema sc t)