1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#!../../../liquidsoap
%ifdef sqlite
# open-begin
db = sqlite("/tmp/database.sql")
# open-end
# drop-begin
db.table.drop("metadata")
# drop-end
# create-begin
db.table.create(
"metadata",
preserve=true,
[
(
"filename",
"STRING PRIMARY KEY"
),
("artist", "STRING"),
("title", "STRING"),
("year", "INT")
]
)
# create-end
# insert-begin
db.insert(
table="metadata",
{
artist="Naps",
title=
"Best life",
year=2021,
filename="naps.mp3"
}
)
db.insert(
table="metadata",
{
artist="Orelsan",
title=
"L'odeur de l'essence",
year=2021,
filename="orelsan.mp3"
}
)
# insert-end
# count-begin
n = db.count(table="metadata", where="year=2023")
# count-end
ignore(n)
# select-begin
l =
db.select(
table="metadata",
where=
"year >= 2000"
)
# select-end
# select2-begin
find_artist = "Brassens"
l' =
db.select(
table="metadata",
where=
"artist = #{sqlite.escape(find_artist)}"
)
# select2-end
ignore(l')
# query-begin
l'' =
db.query(
"SELECT * FROM metadata WHERE artist = 'bla'"
)
# query-end
ignore(l'')
# play-begin
files =
list.map(fun (row) -> null.get(list.assoc("filename", row.to_list())), l)
s = playlist.list(files)
output(s)
# play-end
# play2-begin
def f(row) =
let sqlite.row (r :
{filename: string, artist: string, title: string, year: int}
) = row
r.filename
end
files = list.map(f, l)
s = playlist.list(files)
output(s)
# play2-end
# delete-begin
db.delete(
table="metadata",
where=
"year < 1900"
)
# delete-end
# exec-begin
db.exec(
"DROP TABLE IF EXISTS metadata"
)
# exec-end
%endif
|