ronantakizawa/codereview-bench huggingface dataset:
Repository: docker/compose
File: pkg/compose/build_bake.go (Go)

Code before:

package compose

import (
	"bufio"
	"bytes"
	"context"
	"crypto/sha1"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"os"
	"os/exec"
	"path/filepath"
	"slices"
	"strconv"
	"strings"

	"github.com/compose-spec/compose-go/v2/types"
	"github.com/containerd/errdefs"
	"github.com/docker/cli/cli-plugins/manager"
	"github.com/docker/cli/cli/command"
	"github.com/docker/compose/v2/pkg/api"
	"github.com/docker/compose/v2/pkg/progress"
	"github.com/docker/distribution/uuid"
	"github.com/docker/docker/api/types/versions"
	"github.com/docker/docker/builder/remotecontext/urlutil"
	"github.com/moby/buildkit/client"
	gitutil "github.com/moby/buildkit/frontend/dockerfile/dfgitutil"
	"github.com/moby/buildkit/util/progress/progressui"
	"github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
	"golang.org/x/sync/errgroup"
)

func buildWithBake(dockerCli command.Cli) (bool, error) {
	b, ok := os.LookupEnv("COMPOSE_BAKE")
	if !ok {
		b = "true"
	}
	bake, err := strconv.ParseBool(b)
	if err != nil {
		return false, err
	}
	if !bake {
		if ok {
			logrus.Warnf("COMPOSE_BAKE=false is deprecated, support for internal compose builder will be removed in next release")
		}
		return false, nil
	}

Review comment (suggestion):
don't use this one; docker/distribution is deprecated;

- https://github.com/docker/compose/pull/10953

Code after:

package compose

import (
	"bufio"
	"bytes"
	"context"
	"crypto/sha1"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/fs"
	"os"
	"os/exec"
	"path/filepath"
	"slices"
	"strconv"
	"strings"

	"github.com/compose-spec/compose-go/v2/types"
	"github.com/containerd/errdefs"
	"github.com/docker/cli/cli-plugins/manager"
	"github.com/docker/cli/cli/command"
	"github.com/docker/cli/cli/command/image/build"
	"github.com/docker/compose/v2/pkg/api"
	"github.com/docker/compose/v2/pkg/progress"
	"github.com/google/uuid"
	"github.com/moby/buildkit/client"
	gitutil "github.com/moby/buildkit/frontend/dockerfile/dfgitutil"
	"github.com/moby/buildkit/util/progress/progressui"
	"github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
	"golang.org/x/sync/errgroup"
)

func buildWithBake(dockerCli command.Cli) (bool, error) {
	b, ok := os.LookupEnv("COMPOSE_BAKE")
	if !ok {
		b = "true"
	}
	bake, err := strconv.ParseBool(b)
	if err != nil {
		return false, err
	}
	if !bake {
		if ok {
			logrus.Warnf("COMPOSE_BAKE=false is deprecated, support for internal compose builder will be removed in next release")
		}
		return false, nil
	}
Repository: docker/compose
File: pkg/compose/model.go (Go)

Code before:

	output, err := cmd.CombinedOutput()
	if err != nil {
		return nil, fmt.Errorf("error checking available models: %w", err)
	}

	type AvailableModel struct {
		Id      string   `json:"id"`
		Tags    []string `json:"tags"`
		Created int      `json:"created"`
	}

	models := []AvailableModel{}
	err = json.Unmarshal(output, &models)
	if err != nil {
		return nil, fmt.Errorf("error unmarshalling available models: %w", err)
	}
	var availableModels []string
	for _, model := range models {
		availableModels = append(availableModels, model.Tags...)
	}
	return availableModels, nil
}

// getModelVersion retrieves the docker model CLI version
func (m *modelAPI) getModelVersion(ctx context.Context) (string, error) {
	cmd := exec.CommandContext(ctx, m.path, "version")
	err := m.prepare(ctx, cmd)
	if err != nil {
		return "", err
	}

	output, err := cmd.CombinedOutput()
	if err != nil {
		return "", fmt.Errorf("error getting docker model version: %w", err)
	}

	// Parse output like: "Docker Model Runner version v1.0.4"
	// We need to extract the version string (e.g., "v1.0.4")
	lines := strings.Split(strings.TrimSpace(string(output)), "\n")
	for _, line := range lines {
		if strings.Contains(line, "version") {
			parts := strings.Fields(line)
			for i, part := range parts {
				if part == "version" && i+1 < len(parts) {
					return parts[i+1], nil
				}
			}
		}
	}


Review comment (suggestion):
as docker-model is a CLI plugin, better store plugin version obtained by pluginManager in newModelAPI

Code after:
func (m *modelAPI) ListModels(ctx context.Context) ([]string, error) {
	cmd := exec.CommandContext(ctx, m.path, "ls", "--json")
	err := m.prepare(ctx, cmd)
	if err != nil {
		return nil, err
	}

	output, err := cmd.CombinedOutput()
	if err != nil {
		return nil, fmt.Errorf("error checking available models: %w", err)
	}

	type AvailableModel struct {
		Id      string   `json:"id"`
		Tags    []string `json:"tags"`
		Created int      `json:"created"`
	}

	models := []AvailableModel{}
	err = json.Unmarshal(output, &models)
	if err != nil {
		return nil, fmt.Errorf("error unmarshalling available models: %w", err)
	}
	var availableModels []string
	for _, model := range models {
		availableModels = append(availableModels, model.Tags...)
	}
	return availableModels, nil
}

// supportsRuntimeFlags checks if the docker model version supports runtime flags
// Runtime flags are supported in version >= v1.0.6
func (m *modelAPI) supportsRuntimeFlags() bool {
	// If version is not cached, don't append runtime flags to be safe
	if m.version == "" {
		return false
	}

	// Strip 'v' prefix if present (e.g., "v1.0.6" -> "1.0.6")
	versionStr := strings.TrimPrefix(m.version, "v")
	return !versions.LessThan(versionStr, "1.0.6")
}
Repository: docker/compose
File: pkg/compose/attach.go (Go)

Code before:
func (s *composeService) doAttachContainer(ctx context.Context, service, id, name string, listener api.ContainerEventListener) error {
	inspect, err := s.apiClient().ContainerInspect(ctx, id)
	if err != nil {
		return err
	}

	wOut := utils.GetWriter(func(line string) {
		listener(api.ContainerEvent{
			Type:    api.ContainerEventLog,
			Source:  name,
			ID:      id,
			Service: service,
			Line:    line,
		})
	})
	wErr := utils.GetWriter(func(line string) {
		listener(api.ContainerEvent{
			Type:    api.ContainerEventErr,
			Source:  name,
			ID:      id,
			Service: service,
			Line:    line,
		})
	})

	restore, _, err := s.attachContainerStreams(ctx, id, inspect.Config.Tty, nil, wOut, wErr)
	if err != nil {
		return err
	}
	defer restore()

	return nil
}

//nolint:gocyclo
func (s *composeService) attachContainerStreams(ctx context.Context, container string, tty bool, stdin io.ReadCloser, stdout, stderr io.WriteCloser) (func(), chan bool, error) {
	detached := make(chan bool)
	restore := func() { /* noop */ }
	if stdin != nil {
		in := streams.NewIn(stdin)
		if in.IsTerminal() {
			state, err := term.SetRawTerminal(in.FD())
			if err != nil {
				return restore, detached, err
			}
			restore = func() {
				err := term.RestoreTerminal(in.FD(), state)
				if err != nil {
					logrus.Warnf("failed to restore terminal: %v", err)
				}
			}

Review comment (refactor):
as `attachContainerStreams` is only used by `doAttachContainer` it could be refactored to avoid a restore function being returned (this function signature is a legacy from https://github.com/docker/compose/commit/d4a8e92f462fd21446352cd29841c4e9e16257bc).

Code after:
	if err != nil {
		return err
	}

	wOut := utils.GetWriter(func(line string) {
		listener(api.ContainerEvent{
			Type:    api.ContainerEventLog,
			Source:  name,
			ID:      id,
			Service: service,
			Line:    line,
		})
	})
	wErr := utils.GetWriter(func(line string) {
		listener(api.ContainerEvent{
			Type:    api.ContainerEventErr,
			Source:  name,
			ID:      id,
			Service: service,
			Line:    line,
		})
	})

	err = s.attachContainerStreams(ctx, id, inspect.Config.Tty, wOut, wErr)
	if err != nil {
		return err
	}

	return nil
}

func (s *composeService) attachContainerStreams(ctx context.Context, container string, tty bool, stdout, stderr io.WriteCloser) error {
	streamOut, err := s.getContainerStreams(ctx, container)
	if err != nil {
		return err
	}

	if stdout != nil {
		go func() {
			defer func() {
				if err := stdout.Close(); err != nil {
					logrus.Debugf("failed to close stdout: %v", err)
				}
				if err := stderr.Close(); err != nil {
					logrus.Debugf("failed to close stderr: %v", err)
				}
				if err := streamOut.Close(); err != nil {
					logrus.Debugf("failed to close stream output: %v", err)
				}
			}()
Repository: docker/compose
File: pkg/compose/attach.go (Go)

Code before:
			Source:  name,
			ID:      id,
			Service: service,
			Line:    line,
		})
	})
	wErr := utils.GetWriter(func(line string) {
		listener(api.ContainerEvent{
			Type:    api.ContainerEventErr,
			Source:  name,
			ID:      id,
			Service: service,
			Line:    line,
		})
	})

	err = s.attachContainerStreams(ctx, id, inspect.Config.Tty, wOut, wErr)
	if err != nil {
		return err
	}

	return nil
}

func (s *composeService) attachContainerStreams(ctx context.Context, container string, tty bool, stdout, stderr io.WriteCloser) error {
	_, streamOut, err := s.getContainerStreams(ctx, container)
	if err != nil {
		return err
	}

	if stdout != nil {
		go func() {
			defer func() {
				if err := stdout.Close(); err != nil {
					logrus.Debugf("failed to close stdout: %v", err)
				}
				if err := stderr.Close(); err != nil {
					logrus.Debugf("failed to close stderr: %v", err)
				}
				if err := streamOut.Close(); err != nil {
					logrus.Debugf("failed to close stream output: %v", err)
				}
			}()

			var err error
			if tty {
				_, err = io.Copy(stdout, streamOut)
			} else {
				_, err = stdcopy.StdCopy(stdout, stderr, streamOut)
			}
			if err != nil && !errors.Is(err, io.EOF) {

Review comment (refactor):
it seems to me getContainerStreams is only used from here, so there's another opportunity to simplify/cleanup code by removing useless attachment to stdin

Code after:
			Source:  name,
			ID:      id,
			Service: service,
			Line:    line,
		})
	})
	wErr := utils.GetWriter(func(line string) {
		listener(api.ContainerEvent{
			Type:    api.ContainerEventErr,
			Source:  name,
			ID:      id,
			Service: service,
			Line:    line,
		})
	})

	err = s.attachContainerStreams(ctx, id, inspect.Config.Tty, wOut, wErr)
	if err != nil {
		return err
	}

	return nil
}

func (s *composeService) attachContainerStreams(ctx context.Context, container string, tty bool, stdout, stderr io.WriteCloser) error {
	streamOut, err := s.getContainerStreams(ctx, container)
	if err != nil {
		return err
	}

	if stdout != nil {
		go func() {
			defer func() {
				if err := stdout.Close(); err != nil {
					logrus.Debugf("failed to close stdout: %v", err)
				}
				if err := stderr.Close(); err != nil {
					logrus.Debugf("failed to close stderr: %v", err)
				}
				if err := streamOut.Close(); err != nil {
					logrus.Debugf("failed to close stream output: %v", err)
				}
			}()

			var err error
			if tty {
				_, err = io.Copy(stdout, streamOut)
			} else {
				_, err = stdcopy.StdCopy(stdout, stderr, streamOut)
			}
			if err != nil && !errors.Is(err, io.EOF) {
Repository: docker/compose
File: pkg/watch/watcher_darwin.go (Go)

Code before:
func (d *fseventNotify) initAdd(name string) {
	d.stream.Paths = append(d.stream.Paths, name)

	if d.pathsWereWatching == nil {
		d.pathsWereWatching = make(map[string]any)
	}
	d.pathsWereWatching[name] = struct{}{}
}

func (d *fseventNotify) Start() error {
	if len(d.stream.Paths) == 0 {
		return nil
	}

	numberOfWatches.Add(int64(len(d.stream.Paths)))

	err := d.stream.Start()
	if err != nil {
		return err
	}
	go d.loop()
	return nil
}

func (d *fseventNotify) Close() error {
	d.closeOnce.Do(func() {
		numberOfWatches.Add(int64(-len(d.stream.Paths)))

		d.stream.Stop()
		close(d.errors)
		close(d.stop)
	})

	return nil
}

func (d *fseventNotify) Events() chan FileEvent {
	return d.events
}

func (d *fseventNotify) Errors() chan error {
	return d.errors
}

func newWatcher(paths []string) (Notify, error) {
	dw := &fseventNotify{
		stream: &fsevents.EventStream{
			Latency: 50 * time.Millisecond,
			Flags:   fsevents.FileEvents | fsevents.IgnoreSelf,
			// NOTE(dmiller): this corresponds to the `sinceWhen` parameter in FSEventStreamCreate
			// https://developer.apple.com/documentation/coreservices/1443980-fseventstreamcreate

Review comment (suggestion):
I see there's also a `Start()` - should the `closeOnce` be reset in `Start()` (otherwise it won't be run again after restarting?)


(not sure if that scenario is possible)

Code after:
func (d *fseventNotify) initAdd(name string) {
	d.stream.Paths = append(d.stream.Paths, name)

	if d.pathsWereWatching == nil {
		d.pathsWereWatching = make(map[string]any)
	}
	d.pathsWereWatching[name] = struct{}{}
}

func (d *fseventNotify) Start() error {
	if len(d.stream.Paths) == 0 {
		return nil
	}

	d.closeOnce = sync.Once{}

	numberOfWatches.Add(int64(len(d.stream.Paths)))

	err := d.stream.Start()
	if err != nil {
		return err
	}
	go d.loop()
	return nil
}

func (d *fseventNotify) Close() error {
	d.closeOnce.Do(func() {
		numberOfWatches.Add(int64(-len(d.stream.Paths)))

		d.stream.Stop()
		close(d.errors)
		close(d.stop)
	})

	return nil
}

func (d *fseventNotify) Events() chan FileEvent {
	return d.events
}

func (d *fseventNotify) Errors() chan error {
	return d.errors
}

func newWatcher(paths []string) (Notify, error) {
	dw := &fseventNotify{
		stream: &fsevents.EventStream{
			Latency: 50 * time.Millisecond,
			Flags:   fsevents.FileEvents | fsevents.IgnoreSelf,
Repository: docker/compose
File: pkg/watch/watcher_darwin.go (Go)

Code before:
				}

				d.events <- NewFileEvent(e.Path)
			}
		}
	}
}

// Add a path to be watched. Should only be called during initialization.
func (d *fseventNotify) initAdd(name string) {
	d.stream.Paths = append(d.stream.Paths, name)

	if d.pathsWereWatching == nil {
		d.pathsWereWatching = make(map[string]any)
	}
	d.pathsWereWatching[name] = struct{}{}
}

func (d *fseventNotify) Start() error {
	if len(d.stream.Paths) == 0 {
		return nil
	}

	numberOfWatches.Add(int64(len(d.stream.Paths)))

	err := d.stream.Start()
	if err != nil {
		return err
	}
	go d.loop()
	return nil
}

func (d *fseventNotify) Close() error {
	numberOfWatches.Add(int64(-len(d.stream.Paths)))

	d.stream.Stop()
	close(d.errors)
	close(d.stop)

	return nil
}

func (d *fseventNotify) Events() chan FileEvent {
	return d.events
}

func (d *fseventNotify) Errors() chan error {
	return d.errors
}


Review comment (suggestion):
LOL, not a new problem, but now starting to wonder if either `Start()` should be protected too only run once 🙈 - calling start multiple times wouldn't work well

That's not a new problem though, but perhaps something to look into.


That made me wonder if there's cases where "create watcher" and "start watcher" should be separate; looks like it's used here, and calls `Start` immediately after `NewWatcher` (wondering if `Start` should be done as part of the constructor); https://github.com/docker/compose/blob/bf86ba0e95b626a9e38c25b1dfd4ce232dfd8390/pkg/compose/watch.go#L271-L279

Although I guess it's nice to be able to construct a new watching without immediately starting it in some cases.


Code after:
					// even after we get the HistoryDone event. Skip it.
					continue
				}

				d.events <- NewFileEvent(e.Path)
			}
		}
	}
}

// Add a path to be watched. Should only be called during initialization.
func (d *fseventNotify) initAdd(name string) {
	d.stream.Paths = append(d.stream.Paths, name)

	if d.pathsWereWatching == nil {
		d.pathsWereWatching = make(map[string]any)
	}
	d.pathsWereWatching[name] = struct{}{}
}

func (d *fseventNotify) Start() error {
	if len(d.stream.Paths) == 0 {
		return nil
	}

	d.closeOnce = sync.Once{}

	numberOfWatches.Add(int64(len(d.stream.Paths)))

	err := d.stream.Start()
	if err != nil {
		return err
	}
	go d.loop()
	return nil
}

func (d *fseventNotify) Close() error {
	d.closeOnce.Do(func() {
		numberOfWatches.Add(int64(-len(d.stream.Paths)))

		d.stream.Stop()
		close(d.errors)
		close(d.stop)
	})

	return nil
}

func (d *fseventNotify) Events() chan FileEvent {
	return d.events
Repository: drizzle-team/drizzle-orm
File: drizzle-orm/src/mysql-core/dialect.ts (TypeScript)

Code before:
			const valueList: (SQLChunk | SQL)[] = [];
			colEntries.forEach(([fieldName]) => {
				const colValue = value[fieldName];
				if (typeof colValue === 'undefined') {
					valueList.push(sql`default`);
				} else {
					valueList.push(colValue);
				}
			});
			valuesSqlList.push(valueList);
			if (valueIndex < values.length - 1) {
				valuesSqlList.push(sql`, `);
			}
		});

		const valuesSql = sql.fromList(valuesSqlList);

		const ignoreSql = ignore ? sql`insert ignore` : sql`insert`

		const returningSql = returning
			? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`
			: undefined;

		const onConflictSql = onConflict ? sql` on duplicate key ${onConflict}` : undefined;

		return sql`${ignoreSql} into ${table} ${insertOrder} values ${valuesSql}${onConflictSql}`;
	}

	sqlToQuery(sql: SQL): Query {
		return sql.toQuery({
			escapeName: this.escapeName,
			escapeParam: this.escapeParam,
			escapeString: this.escapeString,
		});
	}
}


Review comment (suggestion):
It's better to do ``sql`insert${ignoreSql}...` `` and use ``sql` ignore` `` or `sql.empty()`/`undefined` for `ignoreSql`. It's more verbose that way.

Code after:
			const valueList: (SQLChunk | SQL)[] = [];
			colEntries.forEach(([fieldName]) => {
				const colValue = value[fieldName];
				if (typeof colValue === 'undefined') {
					valueList.push(sql`default`);
				} else {
					valueList.push(colValue);
				}
			});
			valuesSqlList.push(valueList);
			if (valueIndex < values.length - 1) {
				valuesSqlList.push(sql`, `);
			}
		});

		const valuesSql = sql.fromList(valuesSqlList);

		const ignoreSql = ignore ? sql` ignore` : undefined

		const returningSql = returning
			? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`
			: undefined;

		const onConflictSql = onConflict ? sql` on duplicate key ${onConflict}` : undefined;

		return sql`insert${ignoreSql} into ${table} ${insertOrder} values ${valuesSql}${onConflictSql}`;
	}

	sqlToQuery(sql: SQL): Query {
		return sql.toQuery({
			escapeName: this.escapeName,
			escapeParam: this.escapeParam,
			escapeString: this.escapeString,
		});
	}
}
Repository: drizzle-team/drizzle-orm
File: drizzle-orm/src/mysql-core/dialect.ts (TypeScript)

Code before:
		return `\`${name}\``;
	}

	escapeParam(_num: number): string {
		return `?`;
	}

	escapeString(str: string): string {
		return `'${str.replace(/'/g, "''")}'`;
	}

	buildDeleteQuery({ table, where, returning }: MySqlDeleteConfig): SQL {
		const returningSql = returning
			? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`
			: undefined;

		const whereSql = where ? sql` where ${where}` : undefined;

		return sql`delete from ${table}${whereSql}${returningSql}`;
	}

	buildUpdateSet(table: MySqlTable, set: UpdateSet): SQL {
		const tableColumns = table[Table.Symbol.Columns];

		const columnNames = Object.keys(tableColumns).filter((colName) =>
			!!set[colName] || tableColumns[colName]?.onUpdateFn !== undefined
		);

		const setSize = columnNames.length;
		return sql.join(columnNames.flatMap((colName, i) => {
			const col = tableColumns[colName]!;

			const value = set[colName] ?? sql.param(col.onUpdateFn!(), col);
			const res = sql`${sql.identifier(col.name)} = ${value}`;

			if (i < setSize - 1) {
				return [res, sql.raw(', ')];
			}
			return [res];
		}));
	}

	buildUpdateQuery({ table, set, where, returning }: MySqlUpdateConfig): SQL {
		const setSql = this.buildUpdateSet(table, set);

		const returningSql = returning
			? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`
			: undefined;

		const whereSql = where ? sql` where ${where}` : undefined;


Review comment (suggestion):
`set[colName]` might be `null` which is a valid value I think, but this condition won't work for it. Also, probably a good idea to add setting a null value as a test.

Code after:
		});
	}

	escapeName(name: string): string {
		return `\`${name}\``;
	}

	escapeParam(_num: number): string {
		return `?`;
	}

	escapeString(str: string): string {
		return `'${str.replace(/'/g, "''")}'`;
	}

	private buildWithCTE(queries: Subquery[] | undefined): SQL | undefined {
		if (!queries?.length) return undefined;

		const withSqlChunks = [sql`with `];
		for (const [i, w] of queries.entries()) {
			withSqlChunks.push(sql`${sql.identifier(w[SubqueryConfig].alias)} as (${w[SubqueryConfig].sql})`);
			if (i < queries.length - 1) {
				withSqlChunks.push(sql`, `);
			}
		}
		withSqlChunks.push(sql` `);
		return sql.join(withSqlChunks);
	}

	buildDeleteQuery({ table, where, returning, withList }: MySqlDeleteConfig): SQL {
		const withSql = this.buildWithCTE(withList);

		const returningSql = returning
			? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`
			: undefined;

		const whereSql = where ? sql` where ${where}` : undefined;

		return sql`${withSql}delete from ${table}${whereSql}${returningSql}`;
	}

	buildUpdateSet(table: MySqlTable, set: UpdateSet): SQL {
		const tableColumns = table[Table.Symbol.Columns];

		const columnNames = Object.keys(tableColumns).filter((colName) =>
			set[colName] !== undefined || tableColumns[colName]?.onUpdateFn !== undefined
		);

		const setSize = columnNames.length;
		return sql.join(columnNames.flatMap((colName, i) => {
			const col = tableColumns[colName]!;
Repository: drizzle-team/drizzle-orm
File: drizzle-orm/src/sql/sql.ts (TypeScript)

Code before:
		if (alias === undefined) {
			return this;
		}

		return new SQL.Aliased(this, alias);
	}

	mapWith<
		TDecoder extends
			| DriverValueDecoder<any, any>
			| DriverValueDecoder<any, any>['mapFromDriverValue'],
	>(decoder: TDecoder): SQL<GetDecoderResult<TDecoder>> {
		this.decoder = typeof decoder === 'function' ? { mapFromDriverValue: decoder } : decoder;
		return this as SQL<GetDecoderResult<TDecoder>>;
	}

	inlineParams(): this {
		this.shouldInlineParams = true;
		return this;
	}

	/**
	 * This method is used to conditionally include a part of the query.
	 *
	 * @param condition - Condition to check
	 * @returns SQL if the condition is true, otherwise undefined
	 */
	if(condition: any): this | undefined {
		return condition ? this : undefined;
	}
}

export type GetDecoderResult<T> = T extends Column ? T['_']['data'] : T extends
	| DriverValueDecoder<infer TData, any>
	| DriverValueDecoder<infer TData, any>['mapFromDriverValue'] ? TData
: never;

/**
 * Any DB name (table, column, index etc.)
 */
export class Name implements SQLWrapper {
	static readonly [entityKind]: string = 'Name';

	protected brand!: 'Name';

	constructor(readonly value: string) {}

	getSQL(): SQL<unknown> {
		return new SQL([this]);
	}
}

Review comment (suggestion):
```suggestion
	 * @returns itself if the condition is `true`, otherwise `undefined`
```

Code after:
		if (alias === undefined) {
			return this;
		}

		return new SQL.Aliased(this, alias);
	}

	mapWith<
		TDecoder extends
			| DriverValueDecoder<any, any>
			| DriverValueDecoder<any, any>['mapFromDriverValue'],
	>(decoder: TDecoder): SQL<GetDecoderResult<TDecoder>> {
		this.decoder = typeof decoder === 'function' ? { mapFromDriverValue: decoder } : decoder;
		return this as SQL<GetDecoderResult<TDecoder>>;
	}

	inlineParams(): this {
		this.shouldInlineParams = true;
		return this;
	}

	/**
	 * This method is used to conditionally include a part of the query.
	 *
	 * @param condition - Condition to check
	 * @returns itself if the condition is `true`, otherwise `undefined`
	 */
	if(condition: any | undefined): this | undefined {
		return condition ? this : undefined;
	}
}

export type GetDecoderResult<T> = T extends Column ? T['_']['data'] : T extends
	| DriverValueDecoder<infer TData, any>
	| DriverValueDecoder<infer TData, any>['mapFromDriverValue'] ? TData
: never;

/**
 * Any DB name (table, column, index etc.)
 */
export class Name implements SQLWrapper {
	static readonly [entityKind]: string = 'Name';

	protected brand!: 'Name';

	constructor(readonly value: string) {}

	getSQL(): SQL<unknown> {
		return new SQL([this]);
	}
}