Skip to content

Instantly share code, notes, and snippets.

View rpromyshlennikov's full-sized avatar

Rodion Promyshlennikov rpromyshlennikov

View GitHub Profile
@rpromyshlennikov
rpromyshlennikov / go_struct_from_tables.sql
Last active September 25, 2019 11:23
Generate Golang struct (model) from Postgres tables
WITH models AS (
WITH data AS (
SELECT
replace(initcap(table_name::text), '_', '') table_name,
replace(initcap(column_name::text), '_', '') column_name,
CASE data_type
WHEN 'timestamp without time zone' THEN 'time.Time'
WHEN 'timestamp with time zone' THEN 'time.Time'
WHEN 'boolean' THEN 'bool'
-- add your own type converters as needed or it will default to 'string'