sascha@14: artifacts.id.nextval=SELECT NEXTVAL('ARTIFACTS_ID_SEQ') sascha@14: sascha@14: artifacts.insert=INSERT INTO artifacts \ sascha@41: (id, gid, creation, last_access, ttl, factory, data) \ sascha@41: VALUES (?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?, ?, ?) sascha@14: sascha@14: artifacts.update=UPDATE artifacts SET last_access = CURRENT_TIMESTAMP, \ sascha@14: data = ? WHERE id = ? sascha@14: sascha@41: artifacts.touch=UPDATE artifacts SET last_access = CURRENT_TIMESTAMP WHERE id = ? sascha@14: sascha@314: artifacts.outdated=SELECT id, factory, data, gid FROM artifacts WHERE ttl IS NOT NULL \ sascha@195: AND DATEDIFF('MILLISECOND', last_access, CURRENT_TIMESTAMP) > ttl \ ingo@197: AND id NOT IN (SELECT DISTINCT artifact_id FROM collection_items) \ sascha@231: AND id NOT IN ($LOCKED_IDS$) \ sascha@195: LIMIT 50 sascha@14: sascha@243: artifacts.select.gid=SELECT id, ttl, factory, data FROM artifacts WHERE gid = ?::uuid \ sascha@242: AND (ttl IS NULL \ sascha@242: OR (DATEDIFF('MILLISECOND', last_access, CURRENT_TIMESTAMP) <= ttl) \ sascha@243: OR id IN (SELECT artifact_id FROM collection_items)) sascha@14: ingo@80: artifacts.get.id=SELECT id FROM artifacts WHERE gid = ? 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@14: 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@173: 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 = ? sascha@124: users.select.gid=SELECT id, name, role FROM users WHERE gid = ? 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: ingo@187: collection.check.artifact=SELECT id FROM collection_items \ sascha@176: WHERE artifact_id = ? AND collection_id = ? sascha@176: sascha@176: # COLLECTION ITEMS sascha@176: collection.items.id.nextval=SELECT NEXTVAL('COLLECTION_ITEMS_ID_SEQ') sascha@176: ingo@187: collection.items.insert=INSERT INTO collection_items \ ingo@274: (id, collection_id, artifact_id, attribute, creation) \ ingo@274: VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP) sascha@176: sascha@178: collection.item.get.attribute= \ ingo@187: SELECT ci.attribute FROM collection_items ci \ ingo@191: INNER JOIN collections c ON ci.collection_id = c.id \ ingo@191: INNER JOIN artifacts a ON ci.artifact_id = a.id \ sascha@178: WHERE c.gid = ? AND a.gid = ? sascha@178: sascha@179: collection.item.set.attribute= \ ingo@187: UPDATE collection_items SET attribute = ? WHERE id IN ( \ ingo@187: SELECT ci.id FROM collection_items ci \ ingo@191: INNER JOIN collections c ON ci.collection_id = c.id \ ingo@191: INNER JOIN artifacts a ON ci.artifact_id = a.id \ sascha@179: WHERE c.gid = ? AND a.gid = ?) sascha@179: sascha@180: collection.item.id.cid.aid= \ sascha@193: SELECT ci.id, ci.collection_id, ci.artifact_id FROM collection_items ci \ sascha@193: INNER JOIN collections c ON ci.collection_id = c.id \ sascha@193: INNER JOIN artifacts a ON ci.artifact_id = a.id \ sascha@180: WHERE c.gid = ? AND a.gid = ? sascha@180: sascha@180: collection.item.outdate.artifact= \ sascha@180: UPDATE artifacts \ sascha@180: SET last_access = DATEADD('MILLISECOND', -2, CURRENT_TIMESTAMP), ttl = 1 \ sascha@180: WHERE id = ? AND \ felix@340: NOT EXISTS \ sascha@193: (SELECT id FROM collection_items WHERE collection_id <> ? AND artifact_id = ?) sascha@180: ingo@187: collection.item.delete=DELETE FROM collection_items WHERE id = ? sascha@180: sascha@184: collection.items.list.gid= \ ingo@187: SELECT a.gid, ci.attribute FROM collection_items ci \ sascha@184: INNER JOIN artifacts a ON ci.artifact_id = a.id \ ingo@274: WHERE ci.collection_id IN (SELECT id FROM collections WHERE gid = ?) \ ingo@274: ORDER BY ci.creation sascha@184: sascha@144: # COLLECTIONS sascha@229: sascha@232: collections.outdated= \ sascha@314: SELECT c.id, c.gid FROM collections c \ sascha@232: INNER JOIN collection_items ci ON c.id = ci.collection_id \ sascha@232: INNER JOIN artifacts a ON ci.artifact_id = a.id \ sascha@232: WHERE c.ttl IS NOT NULL \ sascha@232: AND DATEDIFF('MILLISECOND', c.last_access, CURRENT_TIMESTAMP) > c.ttl \ sascha@232: AND a.id NOT IN ($LOCKED_IDS$) sascha@232: sascha@319: collections.update.ttl=UPDATE collections SET ttl = ? WHERE gid = ? ingo@273: ingo@275: collections.update.name=UPDATE collections SET name = ? WHERE gid = ? ingo@275: sascha@229: collections.touch.trigger.function = \ sascha@229: UPDATE collections SET last_access = current_timestamp \ sascha@229: WHERE id IN \ sascha@229: (SELECT c.id FROM collections c \ sascha@229: INNER JOIN collection_items ci ON c.id = ci.collection_id \ sascha@229: INNER JOIN artifacts a ON a.id = ci.artifact_id \ sascha@229: WHERE a.id = ?) sascha@229: sascha@179: collections.touch.by.gid =\ ingo@191: UPDATE collections SET last_access = CURRENT_TIMESTAMP \ sascha@179: WHERE gid = ? sascha@179: sascha@180: collections.touch.by.id =\ ingo@191: UPDATE collections SET last_access = CURRENT_TIMESTAMP \ sascha@180: WHERE id = ? sascha@180: sascha@159: collections.id.nextval=SELECT NEXTVAL('COLLECTIONS_ID_SEQ') sascha@144: sascha@175: collections.id.by.gid=SELECT id FROM collections WHERE gid = ? 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@199: INSERT INTO collections \ sascha@199: (id, gid, name, owner_id, creation, last_access, ttl, attribute) \ sascha@199: VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?, ?) sascha@159: sascha@170: collection.creation.time=SELECT creation from collections WHERE id = ? sascha@170: felix@343: collections.artifacts.oldest=SELECT a.gid, ci.artifact_id \ felix@343: FROM artifacts AS a, collection_items AS ci, collections AS c \ felix@343: WHERE ci.collection_id = c.id AND c.gid = ?::uuid AND ci.artifact_id = a.id \ felix@343: ORDER BY ci.creation felix@343: sascha@167: collections.select.user= \ ingo@281: SELECT c.gid, c.name, c.creation, u.gid, c.ttl FROM \ ingo@181: collections c LEFT OUTER JOIN users u ON c.owner_id = u.id \ sascha@167: WHERE u.gid = ? sascha@167: sascha@167: collections.select.all= \ ingo@281: SELECT c.gid, c.name, c.creation, u.gid, c.ttl FROM \ ingo@181: collections c LEFT OUTER JOIN users u ON c.owner_id = u.id sascha@167: ingo@215: collections.select.by.gid= \ ingo@281: SELECT id, name, owner_id, creation, last_access, attribute, ttl \ ingo@215: FROM collections WHERE gid = ? ingo@215: 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: users.delete.all.collections=DELETE FROM collections WHERE owner_id = ? sascha@144: sascha@159: 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 = DATEADD('MILLISECOND', -2, CURRENT_TIMESTAMP), 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 = DATEADD('MILLISECOND', -2, CURRENT_TIMESTAMP), 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 <> ?))) ingo@253: ingo@253: collection.get.attribute= \ ingo@253: SELECT c.attribute FROM collections c WHERE c.gid = ? ingo@253: ingo@253: collection.set.attribute= \ ingo@253: UPDATE collections SET attribute = ? WHERE gid = ? sascha@303: sascha@303: all.artifacts = \ sascha@320: SELECT u.gid AS u_gid, c.gid AS c_gid, c.name AS c_name, c.creation as c_creation, \ sascha@320: a.gid AS a_gid, a.factory AS factory, a.creation AS a_creation, a.data AS data \ sascha@317: FROM \ sascha@303: users u INNER JOIN collections c ON u.id = c.owner_id \ sascha@303: INNER JOIN collection_items ci ON c.id = ci.collection_id \ sascha@308: INNER JOIN artifacts a ON a.id = ci.artifact_id \ sascha@303: ORDER BY u_gid, c_gid