Commit 397e42e4 authored by Sophie Herold's avatar Sophie Herold 🌼

Adds inquire types support

parent e4172157
Pipeline #824 passed with stage
in 4 minutes and 7 seconds
......@@ -84,25 +84,25 @@ library
Paths_hamsql
build-depends:
aeson >=1.2 && <1.3,
aeson == 1.2.*,
base >=4.8 && <5.0,
bytestring >=0.10 && <0.11,
containers >=0.5 && <0.6,
directory >=1.3 && <1.4,
bytestring == 0.10.*,
containers == 0.5.*,
directory == 1.3.*,
directory-tree == 0.12.1.*,
doctemplates >=0.1 && <0.2,
file-embed >=0.0 && <0.1,
filepath >=1.4 && <1.5,
frontmatter >=0.1 && <0.2,
network-uri >=2.6 && <2.7,
optparse-applicative >=0.13 && <0.14,
doctemplates == 0.2.*,
edit-distance == 0.2.*,
file-embed == 0.0.*,
filepath == 1.4.*,
frontmatter == 0.1.*,
network-uri == 2.6.*,
optparse-applicative == 0.14.*,
postgresql-simple >=0.4 && <0.6,
text >=1.2 && <1.3,
transformers >=0.5 && <0.6,
unordered-containers >=0.2 && <0.3,
yaml >=0.8 && <0.9,
pretty-simple,
edit-distance
pretty-simple == 2.0.*,
text == 1.2.*,
transformers == 0.5.*,
unordered-containers == 0.2.*,
yaml >= 0.8.24 && <0.9
ghc-options:
-Wall
......@@ -145,7 +145,7 @@ test-suite hamsql-tests
tasty,
tasty-hunit,
-- dev
hindent == 5.2.3
hindent
ghc-options:
-Wall
-Wcompat
......
......@@ -32,6 +32,7 @@ deployedSchemas = do
sequences <- deployedSequences schema
functions <- deployedFunctions schema
domains <- deployedDomains schema
types <- deployedTypes schema
return
Schema
{ schemaName = schema
......@@ -52,7 +53,7 @@ deployedSchemas = do
, schemaPrivExecuteAll = Nothing
, schemaPrivAllAll = Nothing
, schemaDomains = presetEmpty domains
, schemaTypes = Nothing
, schemaTypes = presetEmpty types
, schemaExecPostInstall = Nothing
, schemaExecPostInstallAndUpgrade = Nothing
}
......@@ -322,15 +323,15 @@ deployedDomainConstraints dom = do
}
qry =
[sql|
SELECT
conname,
pg_catalog.obj_description(c.oid, 'pg_constraint')::text AS condesc,
consrc
FROM pg_catalog.pg_constraint c
JOIN pg_type t ON t.oid = contypid
WHERE
t.oid = ?::regtype::oid
|]
SELECT
conname,
pg_catalog.obj_description(c.oid, 'pg_constraint')::text AS condesc,
consrc
FROM pg_catalog.pg_constraint c
JOIN pg_type t ON t.oid = contypid
WHERE
t.oid = ?::regtype::oid
|]
deployedSequences :: SqlName -> SqlT [Sequence]
deployedSequences schema = do
......@@ -366,6 +367,37 @@ deployedSequences schema = do
"min_value, cache_value, is_cycled::bool, ?::text AS desc FROM " <>
n
deployedTypes :: SqlName -> SqlT [Type]
deployedTypes schema = do
types <- psqlQry qry (Only $ toSqlCode schema)
mapM toType types
where
toType (typname, typdesc) = do
elements <- map toElement <$> deployedColumns (schema, typname)
return $
Type
{ typeName = typname
, typeDescription = fromMaybe "" typdesc
, typeElements = elements
}
toElement x =
TypeElement
{typeelementName = columnName x, typeelementType = columnType x}
qry =
[sql|
SELECT
typname,
pg_catalog.obj_description(oid, 'pg_type')::text AS desc
-- typdefault
FROM pg_type
WHERE
typtype = 'c'
AND typisdefined
AND (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c
WHERE c.oid = typrelid)
AND typnamespace = ?::regnamespace::oid
|]
sqlManageSchemaJoin :: Text -> Text
sqlManageSchemaJoin schemaid =
" JOIN pg_namespace AS n " <\> " ON" <-> schemaid <-> "= n.oid AND " <\>
......
name: t_plant
description: |
Stores numbers of ``flowers`` and ``leaves`` of a plant.
elements:
-
name: flowers
type: integer
-
name: leaves
type: integer
name: t_xtype
description: |
Stores numbers of ``flowers`` and ``leaves`` of a plant.
elements:
-
name: flowers
type: integer
-
name: leaves
type: '"self-test".t_plant'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment