Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions drivers/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,17 +546,18 @@ WHERE t.table_schema = ?
return nil
}

const queryFunctions = `SELECT r.routine_schema as database_name,
r.routine_name,
const queryFunctions = `SELECT r.routine_schema AS database_name, r.routine_name,
r.routine_type AS type,
r.data_type AS return_type,
GROUP_CONCAT(CONCAT(p.parameter_name, ' ', p.data_type) SEPARATOR '; ') AS parameter
GROUP_CONCAT(CONCAT(p.parameter_name, ' ', p.data_type) SEPARATOR '; ') AS parameter,
r.routine_comment AS comment
FROM information_schema.routines r
LEFT JOIN information_schema.parameters p
ON p.specific_schema = r.routine_schema
AND p.specific_name = r.specific_name
WHERE routine_schema NOT IN ('sys', 'information_schema', 'mysql', 'performance_schema')
GROUP BY r.routine_schema, r.routine_name, r.routine_type, r.data_type, r.routine_definition`
ON p.specific_schema = r.routine_schema
AND p.specific_name = r.specific_name
WHERE r.routine_schema NOT IN ('sys', 'information_schema', 'mysql', 'performance_schema')
GROUP BY r.routine_schema, r.routine_name, r.routine_type, r.data_type, r.routine_comment
ORDER BY r.routine_schema, r.routine_name;`

func (m *Mysql) getFunctions() ([]*schema.Function, error) {
functions := []*schema.Function{}
Expand All @@ -573,8 +574,9 @@ func (m *Mysql) getFunctions() ([]*schema.Function, error) {
typeValue string
returnType string
arguments sql.NullString
comment sql.NullString
)
err := functionsResult.Scan(&databaseName, &name, &typeValue, &returnType, &arguments)
err := functionsResult.Scan(&databaseName, &name, &typeValue, &returnType, &arguments, &comment)
if err != nil {
return functions, errors.WithStack(err)
}
Expand All @@ -583,6 +585,7 @@ func (m *Mysql) getFunctions() ([]*schema.Function, error) {
Type: typeValue,
ReturnType: returnType,
Arguments: arguments.String,
Comment: comment.String,
}

functions = append(functions, subroutine)
Expand Down
26 changes: 16 additions & 10 deletions drivers/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,24 +400,28 @@ const queryFunctions95 = `SELECT
p.proname AS specific_name,
TEXT 'FUNCTION',
t.typname AS return_type,
pg_get_function_arguments(p.oid) AS arguments
pg_get_function_arguments(p.oid) AS arguments,
d.description AS description
FROM pg_proc AS p
LEFT JOIN pg_namespace AS n ON p.pronamespace = n.oid
LEFT JOIN pg_type AS t ON t.oid = p.prorettype
LEFT JOIN pg_description d ON d.objoid = p.oid
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY p.oid;`
ORDER BY n.nspname, p.proname;`

const queryFunctions = `SELECT
n.nspname AS schema_name,
p.proname AS specific_name,
CASE WHEN p.prokind = 'p' THEN TEXT 'PROCEDURE' ELSE CASE WHEN p.prokind = 'f' THEN TEXT 'FUNCTION' ELSE CAST(p.prokind AS TEXT) END END,
t.typname AS return_type,
pg_get_function_arguments(p.oid) AS arguments
pg_get_function_arguments(p.oid) AS arguments,
d.description AS description
FROM pg_proc AS p
LEFT JOIN pg_namespace AS n ON p.pronamespace = n.oid
LEFT JOIN pg_type AS t ON t.oid = p.prorettype
LEFT JOIN pg_description d ON d.objoid = p.oid
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY p.oid;`
ORDER BY n.nspname, p.proname;`

const queryStoredProcedureSupported = `SELECT column_name
FROM information_schema.columns
Expand Down Expand Up @@ -477,13 +481,14 @@ func (p *Postgres) getFunctionsByQuery(query string) ([]*schema.Function, error)

for functionsResult.Next() {
var (
schemaName string
name string
typeValue string
returnType string
arguments sql.NullString
schemaName string
name string
typeValue string
returnType string
arguments sql.NullString
description sql.NullString
)
err := functionsResult.Scan(&schemaName, &name, &typeValue, &returnType, &arguments)
err := functionsResult.Scan(&schemaName, &name, &typeValue, &returnType, &arguments, &description)
if err != nil {
return functions, errors.WithStack(err)
}
Expand All @@ -492,6 +497,7 @@ func (p *Postgres) getFunctionsByQuery(query string) ([]*schema.Function, error)
Type: typeValue,
ReturnType: returnType,
Arguments: arguments.String,
Comment: description.String,
}

functions = append(functions, function)
Expand Down
4 changes: 3 additions & 1 deletion output/md/md.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,9 @@ func (m *Md) functionsData(functions []*schema.Function, number, adjust bool) []
m.config.MergedDict.Lookup("ReturnType"),
m.config.MergedDict.Lookup("Arguments"),
m.config.MergedDict.Lookup("Type"),
m.config.MergedDict.Lookup("Comment"),
}
headerLine := []string{"----", "-------", "-------", "----"}
headerLine := []string{"----", "-------", "-------", "----", "-------"}
data = append(data,
header,
headerLine,
Expand All @@ -863,6 +864,7 @@ func (m *Md) functionsData(functions []*schema.Function, number, adjust bool) []
f.ReturnType,
f.Arguments,
f.Type,
f.Comment,
}
data = append(data, d)
}
Expand Down
8 changes: 4 additions & 4 deletions sample/detect_relations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Sample database document.

## Stored procedures and functions

| Name | ReturnType | Arguments | Type |
| ---- | ------- | ------- | ---- |
| CustomerLevel | varchar | credit decimal | FUNCTION |
| GetAllComments | | | PROCEDURE |
| Name | ReturnType | Arguments | Type | Comment |
| ---- | ------- | ------- | ---- | ------- |
| CustomerLevel | varchar | credit decimal | FUNCTION | Determines customer tier (PLATINUM, GOLD, SILVER) based on the credit amount |
| GetAllComments | | | PROCEDURE | Retrieves all rows from the comments table |

## Relations

Expand Down
6 changes: 4 additions & 2 deletions sample/detect_relations/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -797,13 +797,15 @@
"name": "CustomerLevel",
"return_type": "varchar",
"arguments": "credit decimal",
"type": "FUNCTION"
"type": "FUNCTION",
"comment": "Determines customer tier (PLATINUM, GOLD, SILVER) based on the credit amount"
},
{
"name": "GetAllComments",
"return_type": "",
"arguments": "",
"type": "PROCEDURE"
"type": "PROCEDURE",
"comment": "Retrieves all rows from the comments table"
}
],
"driver": {
Expand Down
8 changes: 4 additions & 4 deletions sample/detect_relations_singular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Sample database document.

## Stored procedures and functions

| Name | ReturnType | Arguments | Type |
| ---- | ------- | ------- | ---- |
| CustomerLevel | varchar | credit decimal | FUNCTION |
| GetAllComments | | | PROCEDURE |
| Name | ReturnType | Arguments | Type | Comment |
| ---- | ------- | ------- | ---- | ------- |
| CustomerLevel | varchar | credit decimal | FUNCTION | Determines customer tier (PLATINUM, GOLD, SILVER) based on the credit amount |
| GetAllComments | | | PROCEDURE | Retrieves all rows from the comments table |

## Relations

Expand Down
6 changes: 4 additions & 2 deletions sample/detect_relations_singular/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -797,13 +797,15 @@
"name": "CustomerLevel",
"return_type": "varchar",
"arguments": "credit decimal",
"type": "FUNCTION"
"type": "FUNCTION",
"comment": "Determines customer tier (PLATINUM, GOLD, SILVER) based on the credit amount"
},
{
"name": "GetAllComments",
"return_type": "",
"arguments": "",
"type": "PROCEDURE"
"type": "PROCEDURE",
"comment": "Retrieves all rows from the comments table"
}
],
"driver": {
Expand Down
8 changes: 4 additions & 4 deletions sample/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Sample database document.

## Stored procedures and functions

| Name | ReturnType | Arguments | Type |
| ---- | ------- | ------- | ---- |
| CustomerLevel | varchar | credit decimal | FUNCTION |
| GetAllComments | | | PROCEDURE |
| Name | ReturnType | Arguments | Type | Comment |
| ---- | ------- | ------- | ---- | ------- |
| CustomerLevel | varchar | credit decimal | FUNCTION | Determines customer tier (PLATINUM, GOLD, SILVER) based on the credit amount |
| GetAllComments | | | PROCEDURE | Retrieves all rows from the comments table |

## Relations

Expand Down
6 changes: 4 additions & 2 deletions sample/mysql/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -969,13 +969,15 @@
"name": "CustomerLevel",
"return_type": "varchar",
"arguments": "credit decimal",
"type": "FUNCTION"
"type": "FUNCTION",
"comment": "Determines customer tier (PLATINUM, GOLD, SILVER) based on the credit amount"
},
{
"name": "GetAllComments",
"return_type": "",
"arguments": "",
"type": "PROCEDURE"
"type": "PROCEDURE",
"comment": "Retrieves all rows from the comments table"
}
],
"driver": {
Expand Down
2 changes: 1 addition & 1 deletion sample/mysql56/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@
]
}
],
"def": "CREATE TABLE `users` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`)\n) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=latin1 COMMENT='Users table'"
"def": "CREATE TABLE `users` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `password` varchar(50) NOT NULL,\n `email` varchar(355) NOT NULL COMMENT 'ex. user@example.com',\n `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n PRIMARY KEY (`id`),\n UNIQUE KEY `username` (`username`),\n UNIQUE KEY `email` (`email`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Users table'"
}
],
"relations": [
Expand Down
2 changes: 1 addition & 1 deletion sample/mysql56/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CREATE TABLE `users` (
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=latin1 COMMENT='Users table'
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Users table'
```

</details>
Expand Down
28 changes: 14 additions & 14 deletions sample/postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ Sample PostgreSQL database document.

## Stored procedures and functions

| Name | ReturnType | Arguments | Type |
| ---- | ------- | ------- | ---- |
| public.uuid_nil | uuid | | FUNCTION |
| public.uuid_ns_dns | uuid | | FUNCTION |
| public.uuid_ns_url | uuid | | FUNCTION |
| public.uuid_ns_oid | uuid | | FUNCTION |
| public.uuid_ns_x500 | uuid | | FUNCTION |
| public.uuid_generate_v1 | uuid | | FUNCTION |
| public.uuid_generate_v1mc | uuid | | FUNCTION |
| public.uuid_generate_v3 | uuid | namespace uuid, name text | FUNCTION |
| public.uuid_generate_v4 | uuid | | FUNCTION |
| public.uuid_generate_v5 | uuid | namespace uuid, name text | FUNCTION |
| public.update_updated | trigger | | FUNCTION |
| public.reset_comment | void | IN comment_id integer | PROCEDURE |
| Name | ReturnType | Arguments | Type | Comment |
| ---- | ------- | ------- | ---- | ------- |
| public.reset_comment | void | IN comment_id integer | PROCEDURE | Updates the comment field to "updated" for a given comment ID and commits the change. |
| public.update_updated | trigger | | FUNCTION | Trigger function that automatically sets the updated column to the current timestamp whenever a row is updated. |
| public.uuid_generate_v1 | uuid | | FUNCTION | |
| public.uuid_generate_v1mc | uuid | | FUNCTION | |
| public.uuid_generate_v3 | uuid | namespace uuid, name text | FUNCTION | |
| public.uuid_generate_v4 | uuid | | FUNCTION | |
| public.uuid_generate_v5 | uuid | namespace uuid, name text | FUNCTION | |
| public.uuid_nil | uuid | | FUNCTION | |
| public.uuid_ns_dns | uuid | | FUNCTION | |
| public.uuid_ns_oid | uuid | | FUNCTION | |
| public.uuid_ns_url | uuid | | FUNCTION | |
| public.uuid_ns_x500 | uuid | | FUNCTION | |

## Enums

Expand Down
50 changes: 26 additions & 24 deletions sample/postgres/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1289,76 +1289,78 @@
],
"functions": [
{
"name": "public.uuid_nil",
"return_type": "uuid",
"name": "public.reset_comment",
"return_type": "void",
"arguments": "IN comment_id integer",
"type": "PROCEDURE",
"comment": "Updates the comment field to \"updated\" for a given comment ID and commits the change."
},
{
"name": "public.update_updated",
"return_type": "trigger",
"arguments": "",
"type": "FUNCTION"
"type": "FUNCTION",
"comment": "Trigger function that automatically sets the updated column to the current timestamp whenever a row is updated."
},
{
"name": "public.uuid_ns_dns",
"name": "public.uuid_generate_v1",
"return_type": "uuid",
"arguments": "",
"type": "FUNCTION"
},
{
"name": "public.uuid_ns_url",
"name": "public.uuid_generate_v1mc",
"return_type": "uuid",
"arguments": "",
"type": "FUNCTION"
},
{
"name": "public.uuid_ns_oid",
"name": "public.uuid_generate_v3",
"return_type": "uuid",
"arguments": "",
"arguments": "namespace uuid, name text",
"type": "FUNCTION"
},
{
"name": "public.uuid_ns_x500",
"name": "public.uuid_generate_v4",
"return_type": "uuid",
"arguments": "",
"type": "FUNCTION"
},
{
"name": "public.uuid_generate_v1",
"name": "public.uuid_generate_v5",
"return_type": "uuid",
"arguments": "",
"arguments": "namespace uuid, name text",
"type": "FUNCTION"
},
{
"name": "public.uuid_generate_v1mc",
"name": "public.uuid_nil",
"return_type": "uuid",
"arguments": "",
"type": "FUNCTION"
},
{
"name": "public.uuid_generate_v3",
"name": "public.uuid_ns_dns",
"return_type": "uuid",
"arguments": "namespace uuid, name text",
"arguments": "",
"type": "FUNCTION"
},
{
"name": "public.uuid_generate_v4",
"name": "public.uuid_ns_oid",
"return_type": "uuid",
"arguments": "",
"type": "FUNCTION"
},
{
"name": "public.uuid_generate_v5",
"name": "public.uuid_ns_url",
"return_type": "uuid",
"arguments": "namespace uuid, name text",
"arguments": "",
"type": "FUNCTION"
},
{
"name": "public.update_updated",
"return_type": "trigger",
"name": "public.uuid_ns_x500",
"return_type": "uuid",
"arguments": "",
"type": "FUNCTION"
},
{
"name": "public.reset_comment",
"return_type": "void",
"arguments": "IN comment_id integer",
"type": "PROCEDURE"
}
],
"enums": [
Expand Down
Loading
Loading