Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DefaultAlias option to TableSQLBuilder #259

Merged
merged 1 commit into from
Aug 3, 2023

Conversation

quirell
Copy link
Contributor

@quirell quirell commented Aug 3, 2023

The following code

func generateJetTypes(connectionString string) error {
	return jet.GenerateDSN(connectionString, "public", "gen", template.Default(postgres.Dialect).
		UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
			return template.DefaultSchema(schemaMetaData)
			.UseSQLBuilder(template.DefaultSQLBuilder().
				UseTable(func(table metadata.Table) template.TableSQLBuilder {
					return template.DefaultTableSQLBuilder(table).UseDefaultAlias(strings.Trim(table.Name, "s"))
				}))
		}))
}

generates the following output

(...)
var Users = newUsersTable("public", "users", "user")

type usersTable struct {
(...)

for the following table

CREATE TABLE users (
    id UUID PRIMARY KEY,
    name character varying(45) NOT NULL,
    surname character varying(45) NOT NULL,
    updated_at timestamp without time zone NOT NULL,
    created_at timestamp without time zone NOT NULL
);

@codecov-commenter
Copy link

Codecov Report

Merging #259 (39f9996) into master (a2eb15e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@           Coverage Diff           @@
##           master     #259   +/-   ##
=======================================
  Coverage   90.55%   90.55%           
=======================================
  Files         124      124           
  Lines        7060     7064    +4     
=======================================
+ Hits         6393     6397    +4     
  Misses        515      515           
  Partials      152      152           
Files Changed Coverage Δ
generator/template/sql_builder_template.go 87.27% <100.00%> (+0.48%) ⬆️

@go-jet
Copy link
Owner

go-jet commented Aug 3, 2023

Looks good.

@go-jet go-jet merged commit 3333358 into go-jet:master Aug 3, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants