=====
Usage
=====

To use LookML Generator in a project::

    from lookmlgen.view import View
    from lookmlgen.field import Dimension, DimensionGroup, Measure
    from lookmlgen.base_generator import GeneratorFormatOptions

    view_name = 'my_view'
    v = View(view_name, sql_table_name='my_table')
    v.add_field(Dimension('id', type='number', primary_key=True))
    v.add_field(DimensionGroup('created'))
    v.add_field(Dimension('name'))
    v.add_field(Dimension('quantity', type='number'))
    v.add_field(Measure('total_quantity', sql='${TABLE}.quantity', type='sum'))

    with open('%s.view.lkml' % view_name, 'w') as f:
        v.generate_lookml(f, GeneratorFormatOptions(view_fields_alphabetical=False))

The contents of the file 'my_view.view.lkml' will be::

    # STOP! This file was generated by an automated process.
    # Any edits you make will be lost the next time it is
    # re-generated.
    view: my_view {
      sql_table_name: my_table ;;

      dimension: id {
        type: number
        primary_key: yes
        sql: ${TABLE}.id ;;
      }

      dimension_group: created {
        type: time
        timeframes: ["time", "date", "week", "month"]
        datatype: datetime
        sql: ${TABLE}.created ;;
      }

      dimension: name {
        sql: ${TABLE}.name ;;
      }

      dimension: quantity {
        type: number
        sql: ${TABLE}.quantity ;;
      }

      measure: total_quantity {
        type: sum
        sql: ${TABLE}.quantity ;;
      }
    }
