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@41: artifacts.outdated=SELECT id, factory, data FROM artifacts WHERE ttl IS NOT NULL \ sascha@43: AND DATEDIFF('MILLISECOND', last_access, CURRENT_TIMESTAMP) > ttl LIMIT 50 sascha@14: sascha@41: artifacts.select.gid=SELECT id, last_access, ttl, factory, data FROM artifacts WHERE gid = ? 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@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 = ? 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: sascha@144: # COLLECTIONS sascha@144: 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@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@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 = 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 <> ?)))