-- @block create table
CREATE TABLE zeiten (
    id SERIAL PRIMARY KEY,
    logged_time TIMESTAMP DEFAULT NOW(),
    card_id VARCHAR,
    reader_id VARCHAR,
    booking_type INTEGER
);
-- @block insert data
INSERT INTO zeiten (card_id, reader_id, booking_type)
VALUES ('test_card', 'test_reader', '2')
RETURNING id, logged_time;
-- @block select
SELECT *
FROM zeiten;
-- @block select last entry from card id
SELECT *
FROM "zeiten"
WHERE "card_id" = 'test_card'
    AND "logged_time" >= now()::date + interval '1h'
ORDER BY "logged_time" DESC
LIMIT 1;
-- @block delete table
DROP TABLE IF EXISTS zeiten;
