Skip to content

Customize field column in generated code #1451

Answered by stephenafamo
hpower2 asked this question in Q&A
Discussion options

You must be logged in to vote

Try adding this to your config.

[[types]]
  tables = ['users']

  [types.match]
    name = "email"
    type = "string"

  [types.replace]
    type = "types.EncryptedString"

  [types.imports]
    third_party = ['"github.com/hpower/project/types"']

Make sure to define the Scan and Value methods on the type

package types

import "database/sql/driver"

type EncryptedString string

func (e *EncryptedString) Value() (driver.Value, error) {
	// Encrypt and return the encrypted value
	var encrypted string
	return encrypted, nil
}

func (e *EncryptedString) Scan(src any) error {
	var encrypted string

	switch v := src.(type) {
	case []byte:
		encrypted = string(v)
	case string:
		encrypted = v

	d…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@hpower2
Comment options

@hpower2
Comment options

@stephenafamo
Comment options

Answer selected by stephenafamo
@hpower2
Comment options

@stephenafamo
Comment options

@hpower2
Comment options

@stephenafamo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants