summaryrefslogtreecommitdiff
path: root/sql/modules/Entity.sql
blob: 2b5aed58ad1664573b487882e3366e529d541fdc (plain)
  1. --
  2. BEGIN;
  3. CREATE OR REPLACE FUNCTION entity_save(
  4. in_entity_id int, in_name text, in_entity_class INT
  5. ) RETURNS INT AS $$
  6. DECLARE
  7. e entity;
  8. e_id int;
  9. BEGIN
  10. select * into e from entity where id = in_entity_id;
  11. IF NOT FOUND THEN
  12. -- do the insert magic.
  13. e_id = nextval('entity_id_seq');
  14. insert into entity (id, name, entity_class) values
  15. (e_id,
  16. in_name,
  17. in_entity_class
  18. );
  19. return e_id;
  20. ELSIF FOUND THEN
  21. update
  22. entity
  23. SET
  24. name = in_name
  25. entity_class = in_entity_class
  26. WHERE
  27. id = in_entity_id;
  28. return in_entity_id;
  29. END IF;
  30. END;
  31. $$ language 'plpgsql';
  32. commit;