Skip to content

Alias Command #6331

Closed
Closed

Description

@ChrisTalman

ReQL could benefit from having an alias command.

For instance, MySQL has the following command, which allows for column names to be returned with another name.

SELECT column_name AS alias_name
FROM table_name;

Currently, this can be achieved in ReQL by the following method.

r
  .db('database')
  .table('table')
  .map(
    function(document)
    {
      return document.merge(
        {
          alias: document('key')
        }
      )
    }
  )
  .without('key')

This is very verbose, and could be simplified with an alias command, as follows.

r
  .db('database')
  .table('table')
  .alias('key', 'alias')

The alias command could also accept an object of aliases.

r
  .db('database')
  .table('table')
  .alias(
    {
      keyA: 'aliasA',
      keyB: 'aliasB',
      keyC: 'aliasC'
    }
  )

An alias command could also have the benefit of conveying greater meaning at a glance than an ambiguous map.

Activity

  1. chrisvariety commented on Apr 16, 2017

    @chrisvariety

    You can also write an alias like this, which is slightly less verbose.

    r.db('database').table('table').merge({alias: r.row('key')}).without('key')
    
  2. srh commented on May 17, 2017

    @srh
    Contributor

    This is a dupe of #881.

  3. added this to the duplicate milestone on May 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions