Skip to content

Commit

Permalink
Improves README by adding examples
Browse files Browse the repository at this point in the history
  • Loading branch information
hgouchet committed Jan 10, 2017
1 parent f70e6c9 commit e8c8fb8
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,44 @@

Only the first statement is supported by Adwords API, the others are proposed by the AWQL command line tool.

## Example
## Examples

```go
q := `SELECT CampaignName FROM CAMPAIGN_PERFORMACE_REPORT ORDER BY 1 LIMIT 5\G`
stmts, _ := NewParser(strings.NewReader(q)).Parse()
if stmt, ok := stmts[0].(SelectStmt); ok {
fmt.Println(stmt.OrderList()[0].ColumnName)
// Output: CampaignName
### Unknown single statement.

```go
q := `SELECT CampaignId, CampaignName FROM CAMPAIGN_PERFORMANCE_REPORT;`
stmt, _ := awql.NewParser(strings.NewReader(q)).ParseRow()
if stmt, ok := stmt.(awql.SelectStmt); ok {
fmt.Println(stmt.SourceName())
// Output: CAMPAIGN_PERFORMANCE_REPORT
}
```

### Select statement.

```go
q := `SELECT AdGroupName FROM ADGROUP_PERFORMANCE_REPORT;`
stmt, _ := awql.NewParser(strings.NewReader(q)).ParseSelect()
fmt.Printf("Gets the column named %v from %v.\n", stmt.Columns()[0].Name(), stmt.SourceName())
// Output: Gets the column named AdGroupName from ADGROUP_PERFORMANCE_REPORT.
```

### Multiple statements.

```go
q := `SELECT CampaignName FROM CAMPAIGN_PERFORMANCE_REPORT ORDER BY 1 LIMIT 5\GDESC ADGROUP_PERFORMANCE_REPORT AdGroupName;`
stmts, _ := awql.NewParser(strings.NewReader(q)).Parse()
for _, stmt := range stmts {
switch stmt.(type) {
case awql.SelectStmt:
fmt.Println(stmt.(awql.SelectStmt).OrderList()[0].Name())
case awql.DescribeStmt:
fmt.Println(stmt.(awql.DescribeStmt).SourceName())
fmt.Println(stmt.(awql.DescribeStmt).Columns()[0].Name())
}
}
```
// Output:
// CampaignName
// ADGROUP_PERFORMANCE_REPORT
// AdGroupName
```

0 comments on commit e8c8fb8

Please sign in to comment.