# Music Library ```elixir Mix.install([ {:kino_db, "~> 0.2.10"}, {:exqlite, "~> 0.23.0"}, {:kino_vega_lite, "~> 0.1.11"} ]) ``` ## Setup ```elixir opts = [ database: "/Users/cloud/github.com/cloud8421/music_library/data/music_library_dev.db" ] {:ok, conn} = Kino.start_child({Exqlite, opts}) ``` ## Aggregates ### Count of records per artist ```elixir count_by_artist = Exqlite.query!( conn, ~S""" select json_extract(artist.value, '$.name') as name, count(1) as c from records, json_each(records.artists) artist group by name order by c desc ; """, [] ) ``` ```elixir VegaLite.new(width: 600, title: "Count by Artist") |> VegaLite.data_from_values(count_by_artist, only: ["c", "name"]) |> VegaLite.mark(:bar) |> VegaLite.encode_field(:x, "c", type: :quantitative) |> VegaLite.encode_field(:y, "name", type: :nominal) ``` ### Count of records by genre ```elixir count_by_genre = Exqlite.query!( conn, ~S""" select genre.value, count(genre.value) as c from records, json_each(records.genres) genre group by genre.value order by c desc ; """, [] ) ``` ```elixir VegaLite.new(width: 600, title: "Count by genre") |> VegaLite.data_from_values(count_by_genre, only: ["c", "value"]) |> VegaLite.mark(:bar) |> VegaLite.encode_field(:x, "c", type: :quantitative) |> VegaLite.encode_field(:y, "value", type: :nominal) ```