Skip to content

Conversation

nicksan222
Copy link

This PR adds the flag emit_schema_name.
This will put before all the tables a %s, and will replace them inside the function

The generated result would look something like this

const getItemsByIds = `-- name: GetItemsByIds :many
SELECT id FROM ` + "`" + `%s` + "`" + `.items
ORDER BY ` + "`" + `index` + "`" + ` ASC
`

// Will add schema name as parameter
func (q *Queries) GetItemsByIds(ctx context.Context, schema string) ([]uint32, error) {
        // Will replace at runtime the schema placeholder
	rows, err := q.db.QueryContext(ctx, strings.ReplaceAll(getItemsByIds, "%s", schema))
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []uint32
	for rows.Next() {
		var id uint32
		if err := rows.Scan(&id); err != nil {
			return nil, err
		}
		items = append(items, id)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

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.

1 participant