|
@@ -6,11 +6,11 @@
|
|
|
<div class="grid" style="font-size: 0.8rem">
|
|
|
{#each slice as s}
|
|
|
<div>
|
|
|
- {#if s.Foto}
|
|
|
- <img src="data:image/jpg;base64,{buffer(s.Foto)}" alt="Foto" style="width: 120px">
|
|
|
- {:else}
|
|
|
+ {#await foto(s) then f}
|
|
|
+ <img src="data:image/jpg;base64,{f}" alt="Foto" style="width: 120px">
|
|
|
+ {:catch}
|
|
|
Kein Foto
|
|
|
- {/if}
|
|
|
+ {/await}
|
|
|
<br>
|
|
|
{s.Name}, {s.Vorname}
|
|
|
</div>
|
|
@@ -26,16 +26,15 @@
|
|
|
const mysql = R('mysql')
|
|
|
var connection = mysql.createConnection(knexConfig.connection)
|
|
|
connection.connect()
|
|
|
- $: connection.query({
|
|
|
- sql: 'SELECT Foto, Schueler_ID FROM `schuelerfotos` WHERE `Schueler_ID` IN (?)',
|
|
|
- values: [schueler.map(s => s.ID)]},
|
|
|
- (e, res) => schueler = mergeById(schueler, res))
|
|
|
- const mergeById = (a1, a2) =>
|
|
|
- a1.map(itm => ({
|
|
|
- ...a2.find((item) => (item.Schueler_ID === itm.ID) && item),
|
|
|
- ...itm
|
|
|
- }))
|
|
|
- const buffer = (d) => Buffer.from(d, 'binary').toString('base64')
|
|
|
+ async function foto (s) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ connection.query('SELECT Foto FROM `schuelerfotos` WHERE `Schueler_ID` = ?', [s.ID],
|
|
|
+ (err, rows) => {
|
|
|
+ if (err || rows.length===0) return reject(err);
|
|
|
+ resolve(Buffer.from(rows[0].Foto, 'binary').toString('base64'));
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
</script>
|
|
|
|
|
|
<style>
|