SelectQuery represents a DB-agnostic SELECT query. It can be built into a DB-specific query by calling the Build() method.

Hierarchy

  • SelectQuery

Methods

  • All executes the SELECT query and populates all rows of the result into a slice.

    Note that the slice must be passed in as a pointer.

    If the query does not specify a "from" clause, the method will try to infer the name of the table to be selected from by calling getTableName() which will return either the type name of the slice elements or the TableName() method if the slice element implements the TableModel interface.

    Parameters

    • slice: {}

      Returns void

    • AndGroupBy appends additional columns to the existing GROUP BY clause. Column names will be properly quoted.

      Parameters

      • Rest ...cols: string[]

      Returns SelectQuery

    • AndOrderBy appends additional columns to the existing ORDER BY clause. Column names will be properly quoted. A column name can contain "ASC" or "DESC" to indicate its ordering direction.

      Parameters

      • Rest ...cols: string[]

      Returns SelectQuery

    • AndSelect adds additional columns to be selected. Column names will be automatically quoted.

      Parameters

      • Rest ...cols: string[]

      Returns SelectQuery

    • Build builds the SELECT query and returns an executable Query object.

      Returns Query

    • Column builds and executes the SELECT statement and populates the first column of the result into a slice. Note that the parameter must be a pointer to a slice. This is a shortcut to SelectQuery.Build().Column()

      Parameters

      • a: {}

        Returns void

      • Distinct specifies whether to select columns distinctively. By default, distinct is false.

        Parameters

        • v: boolean

        Returns SelectQuery

      • From specifies which tables to select from. Table names will be automatically quoted.

        Parameters

        • Rest ...tables: string[]

        Returns SelectQuery

      • GroupBy specifies the GROUP BY clause. Column names will be properly quoted.

        Parameters

        • Rest ...cols: string[]

        Returns SelectQuery

      • Join specifies a JOIN clause. The "typ" parameter specifies the JOIN type (e.g. "INNER JOIN", "LEFT JOIN").

        Parameters

        Returns SelectQuery

      • Model selects the row with the specified primary key and populates the model with the row data.

        The model variable should be a pointer to a struct. If the query does not specify a "from" clause, it will use the model struct to determine which table to select data from. It will also use the model to infer the name of the primary key column. Only simple primary key is supported. For composite primary keys, please use Where() to specify the filtering condition.

        Parameters

        • pk: {}
          • model: {}

            Returns void

          • One executes the SELECT query and populates the first row of the result into the specified variable.

            If the query does not specify a "from" clause, the method will try to infer the name of the table to be selected from by calling getTableName() which will return either the variable type name or the TableName() method if the variable implements the TableModel interface.

            Note that when the query has no rows in the result set, an sql.ErrNoRows will be returned.

            Parameters

            • a: {}

              Returns void

            • OrderBy specifies the ORDER BY clause. Column names will be properly quoted. A column name can contain "ASC" or "DESC" to indicate its ordering direction.

              Parameters

              • Rest ...cols: string[]

              Returns SelectQuery

            • Row builds and executes the SELECT query and populates the first row of the result into the specified variables. This is a shortcut to SelectQuery.Build().Row()

              Parameters

              • Rest ...a: {}[]

              Returns void

            • Rows builds and executes the SELECT query and returns a Rows object for data retrieval purpose. This is a shortcut to SelectQuery.Build().Rows()

              Returns dbx.Rows

            • Select specifies the columns to be selected. Column names will be automatically quoted.

              Parameters

              • Rest ...cols: string[]

              Returns SelectQuery

            Properties

            fieldMapper: FieldMapFunc

            FieldMapper maps struct field names to DB column names.

            tableMapper: TableMapFunc

            TableMapper maps structs to DB table names.

            Generated using TypeDoc