sascha@38: artifacts.id.nextval=SELECT nextval('ARTIFACTS_ID_SEQ') sascha@38: sascha@38: artifacts.insert=INSERT INTO artifacts \ sascha@41: (id, gid, creation, last_access, ttl, factory, data) \ sascha@41: VALUES (?, ?::uuid, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?, ?, ?) sascha@38: sascha@38: artifacts.update=UPDATE artifacts SET last_access = CURRENT_TIMESTAMP, \ sascha@38: data = ? WHERE id = ? sascha@38: sascha@41: artifacts.touch=UPDATE artifacts SET last_access = CURRENT_TIMESTAMP WHERE id = ? sascha@38: sascha@41: artifacts.outdated=SELECT id, factory, data FROM artifacts WHERE ttl IS NOT NULL \ sascha@38: AND CURRENT_TIMESTAMP - last_access > (ttl || ' microseconds')::interval LIMIT 50 sascha@38: sascha@41: artifacts.select.gid=SELECT id, last_access, ttl, factory, data FROM artifacts WHERE gid = ?::uuid sascha@38: ingo@80: artifacts.get.id=SELECT id FROM artifacts WHERE gid = ?::uuid ingo@80: ingo@80: artifacts.replace=UPDATE artifacts SET \ ingo@80: creation = CURRENT_TIMESTAMP, last_access = CURRENT_TIMESTAMP, \ ingo@80: ttl = ?, factory = ?, data = ? \ ingo@80: WHERE id = ? ingo@80: sascha@38: artifacts.delete=DELETE FROM artifacts WHERE id = ? sascha@124: sascha@124: # USERS sascha@124: sascha@124: users.id.nextval=SELECT NEXTVAL('USERS_ID_SEQ') sascha@124: sascha@124: users.insert=INSERT INTO users (id, gid, name, role) VALUES (?, ?, ?, ?) sascha@124: sascha@144: users.select.id.by.gid=SELECT id FROM users WHERE gid = ?::uuid sascha@124: users.select.gid=SELECT id, name, role FROM users WHERE gid = ?::uuid sascha@124: sascha@133: users.delete.id=DELETE FROM users WHERE id = ? sascha@124: sascha@124: users.delete.collections=DELETE FROM collections where owner_id = ? sascha@124: sascha@124: users.select.all=SELECT id, gid, name, role FROM users sascha@144: sascha@144: # COLLECTIONS sascha@159: collections.id.nextval=SELECT NEXTVAL('COLLECTIONS_ID_SEQ') sascha@144: sascha@175: collections.id.by.gid=SELECT id FROM collections WHERE gid = ?::uuid sascha@175: sascha@175: delete.collection.items=DELETE FROM collection_items WHERE collection_id = ? sascha@175: sascha@175: delete.collection=DELETE FROM collections WHERE id = ? sascha@175: sascha@144: delete.user.collection.items= \ sascha@144: DELETE FROM collection_items WHERE collection_id IN \ sascha@144: (SELECT id FROM collections WHERE owner_id = ?) sascha@144: sascha@159: collections.insert= \ sascha@159: INSERT INTO collections (id, gid, name, owner_id, creation, last_access, ttl) \ sascha@159: VALUES (?, ?::uuid, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?) sascha@159: sascha@170: collection.creation.time=SELECT creation from collections WHERE id = ? sascha@170: sascha@167: collections.select.user= \ sascha@167: SELECT c.gid, c.name, c.creation, u.gid FROM \ sascha@173: collections c LEFT OUTER JOIN users u ON c.owner_id = u.id \ sascha@167: WHERE u.gid = ?::uuid sascha@167: sascha@167: collections.select.all= \ sascha@167: SELECT c.gid, c.name, c.creation, u.gid FROM \ sascha@173: collections c LEFT OUTER JOIN users u ON c.owner_id = u.id sascha@167: sascha@144: users.collections=SELECT collection_id, gid, name FROM collections WHERE owner_id = ? sascha@144: users.collection.ids=SELECT collection_id FROM collections WHERE owner_id = ? sascha@144: sascha@144: artifacts.in.one.collection.only=\ sascha@144: SELECT artifact_id FROM collection_items\ sascha@144: WHERE collection_id = ? AND\ sascha@144: artifact_id NOT IN (SELECT DISTINCT artifact_id FROM collection_items WHERE collection_id <> ?) sascha@144: sascha@144: outdate.artifacts.collection=UPDATE artifacts \ sascha@144: SET last_access = CURRENT_TIMESTAMP - '2 microseconds'::interval, ttl = 1 \ sascha@144: WHERE id IN \ sascha@144: (SELECT artifact_id FROM collection_items \ sascha@144: WHERE collection_id = ? AND \ sascha@144: artifact_id NOT IN (SELECT DISTINCT artifact_id FROM collection_items WHERE collection_id <> ?)) sascha@144: sascha@144: outdate.artifacts.user=UPDATE artifacts \ sascha@144: SET last_access = CURRENT_TIMESTAMP - '2 microseconds'::interval, ttl = 1 \ sascha@144: WHERE id IN \ sascha@144: (SELECT artifact_id FROM collection_items WHERE \ sascha@144: collection_id IN (SELECT id FROM collections WHERE owner_id = ?) \ sascha@144: AND artifact_id NOT IN \ sascha@144: (SELECT artifact_id FROM collection_items WHERE collection_id IN \ sascha@144: (SELECT id FROM collections WHERE owner_id <> ?))) sascha@144: