added tags (ref #4)
This commit is contained in:
parent
b0be6d6b6e
commit
c5556526b0
@ -1,7 +1,7 @@
|
|||||||
import create_table, rename_column, add_column, types from require "lapis.db.schema"
|
import create_table, rename_column, add_column, types from require "lapis.db.schema"
|
||||||
import trim from require "lapis.util"
|
import trim from require "lapis.util"
|
||||||
import process_tags from require "helpers"
|
import process_tags from require "helpers"
|
||||||
import Tracks from require "models"
|
import Tracks, Tags from require "models"
|
||||||
|
|
||||||
{
|
{
|
||||||
[1]: =>
|
[1]: =>
|
||||||
@ -47,4 +47,20 @@ import Tracks from require "models"
|
|||||||
track.tags = process_tags "untagged" .. tags
|
track.tags = process_tags "untagged" .. tags
|
||||||
else
|
else
|
||||||
track.tags = " untagged "
|
track.tags = " untagged "
|
||||||
|
[5]: =>
|
||||||
|
create_table "tags", {
|
||||||
|
{ "id", types.serial primary_key: true }
|
||||||
|
{ "name", types.text unique: true }
|
||||||
|
{ "count", types.integer default: -1 }
|
||||||
|
}
|
||||||
|
tags = {}
|
||||||
|
for track in *Tracks\select "*"
|
||||||
|
for name in track.tags\gmatch "%S+"
|
||||||
|
if tags[name]
|
||||||
|
tags[name] += 1
|
||||||
|
else
|
||||||
|
tags[name] = 1
|
||||||
|
for name, count in pairs tags
|
||||||
|
Tags\create { :name, :count }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
10
models/Tags.moon
Normal file
10
models/Tags.moon
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import Model, enum from require "lapis.db.model"
|
||||||
|
|
||||||
|
class Tags extends Model
|
||||||
|
-- @kinds: enum {
|
||||||
|
-- other: 1
|
||||||
|
-- artist: 2
|
||||||
|
-- mood: 3
|
||||||
|
-- link: 4
|
||||||
|
-- genre: 5
|
||||||
|
-- }
|
Reference in New Issue
Block a user