Skip to content

Instantly share code, notes, and snippets.

@judell
Last active July 16, 2022 00:05
Show Gist options
  • Save judell/25bf0919cceacab4adce4a12aa0b4298 to your computer and use it in GitHub Desktop.
Save judell/25bf0919cceacab4adce4a12aa0b4298 to your computer and use it in GitHub Desktop.
hackernews_single_item
package hackernews
import (
"context"
"github.com/PaulRosset/go-hacknews"
"github.com/turbot/steampipe-plugin-sdk/v3/plugin"
)
func tableHackernewsSingleItem(ctx context.Context) *plugin.Table {
return &plugin.Table{
Name: "hackernews_single_item",
Description: "Stories, comments, jobs, Ask HNs and even polls are just items. This table includes one Hacker News item.",
List: &plugin.ListConfig {
Hydrate: _getItem,
KeyColumns: plugin.SingleColumn(("id")),
},
Columns: itemCols(),
}
}
func _getItem(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
quals := d.KeyColumnQuals
plugin.Logger(ctx).Warn("hackernews_single_item._getItem", "quals", quals)
id := int(quals["id"].GetInt64Value())
d.StreamListItem(ctx, &hacknews.Post{Id: id})
return nil, nil
}
/*
> with ids as (
select 31820613 as id
union
select 31820635
order by id
)
select
h.id,
h.score,
h.descendants
from
hackernews_single_item h
join
ids i
on
h.id = i.id
+----------+-------+-------------+
| id | score | descendants |
+----------+-------+-------------+
| 31820613 | 17 | 4 |
| 31820635 | 723 | 426 |
+----------+-------+-------------+
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment