Skip to content

Improve select table with @Selection when using AliasName protocol #173

Description

@Playrom

Description

Hi

If I have an alias for a table, that table aliased cannot be used in select when using @selection , because conflicting signatures

I drop an example


struct Example {
    @Table
    struct Wallet {
        public let id: Int
        public let name: String
    }

    @Table
    struct Transfer {
        let id: Int
        let walletId: Int
    }

    enum WalletAlias: AliasName {
        static let aliasName: String = "wallet_alias"
    }

    static let transfers = Transfer
        .join(Wallet.as(WalletAlias.self).all, on: { transfersTable, sourceWallets in
            transfersTable.walletId.eq(sourceWallets.id)
        })

    @Selection
    public struct ExampleSelection1: Sendable {
        public let record: Example.Transfer
        public let sourceWallet: Example.Wallet
    }


    /// Initializer 'init(record:sourceWallet:)' requires the types 'TableAlias<Example.Wallet, Example.WalletAlias>.TableColumns.QueryValue' (aka 'TableAlias<Example.Wallet, Example.WalletAlias>') and 'Example.Wallet' be equivalent
    static let query1 = transfers
        .select { a, b in
            return ExampleSelection1.Columns(record: a, sourceWallet: b)
        }

    @Selection
    public struct ExampleSelection2: Sendable {
        public let record: Example.Transfer
        public let sourceWallet: Example.WalletAlias
    }

    /// Initializer 'init(record:sourceWallet:)' requires the types 'TableAlias<Example.Wallet, Example.WalletAlias>.TableColumns.QueryValue' (aka 'TableAlias<Example.Wallet, Example.WalletAlias>') and 'Example.WalletAlias' be equivalent
    static let query2 = transfers
        .select { a, b in
            return ExampleSelection2.Columns(record: a, sourceWallet: b)
        }
}

Only using this generic combination may result in a compilation, but it is a bit un-usable

@Selection
    public struct ExampleSelection1: Sendable {
        public let record: Example.Transfer
        public let sourceWallet: StructuredQueries.TableAlias<Example.Wallet, Example.WalletAlias>
    }


    /// Initializer 'init(record:sourceWallet:)' requires the types 'TableAlias<Example.Wallet, Example.WalletAlias>.TableColumns.QueryValue' (aka 'TableAlias<Example.Wallet, Example.WalletAlias>') and 'Example.Wallet' be equivalent
    static let query1 = transfers
        .select { a, b in
            return ExampleSelection1.Columns(record: a, sourceWallet: b)
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions