Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rodtanci authored Aug 1, 2024
1 parent a824268 commit 64d1965
Showing 1 changed file with 67 additions and 67 deletions.
134 changes: 67 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,78 +147,78 @@ Antes de iniciar, certifique-se de que você já tem instalado:

***Cria na raiz do banco de dados***

**Função para replicar inserções:**

```sql
CREATE OR REPLACE FUNCTION replicate_labels_to_tags()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO tags (id, name)
VALUES (NEW.id, NEW.title);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
```

**Função para replicar exclusões:**

```sql
CREATE OR REPLACE FUNCTION delete_labels_from_tags_and_taggings()
RETURNS TRIGGER AS $$
BEGIN
-- Exclui da tabela tags
DELETE FROM tags WHERE id = OLD.id;
-- Exclui da tabela taggings
DELETE FROM taggings WHERE tag_id = OLD.id;
RETURN OLD;
END;
$$ LANGUAGE plpgsql;
```

**Função para replicar atualizações:**

```sql
CREATE OR REPLACE FUNCTION update_labels_to_tags()
RETURNS TRIGGER AS $$
BEGIN
UPDATE tags
SET name = NEW.title
WHERE id = NEW.id;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
```
**Função para replicar inserções:**
```sql
CREATE OR REPLACE FUNCTION replicate_labels_to_tags()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO tags (id, name)
VALUES (NEW.id, NEW.title);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
```
**Função para replicar exclusões:**
```sql
CREATE OR REPLACE FUNCTION delete_labels_from_tags_and_taggings()
RETURNS TRIGGER AS $$
BEGIN
-- Exclui da tabela tags
DELETE FROM tags WHERE id = OLD.id;
-- Exclui da tabela taggings
DELETE FROM taggings WHERE tag_id = OLD.id;
RETURN OLD;
END;
$$ LANGUAGE plpgsql;
```
**Função para replicar atualizações:**
```sql
CREATE OR REPLACE FUNCTION update_labels_to_tags()
RETURNS TRIGGER AS $$
BEGIN
UPDATE tags
SET name = NEW.title
WHERE id = NEW.id;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
```

6. **Criação dos Triggers**

***Criar na tabela labels***

**Trigger para inserções:**

```sql
CREATE TRIGGER after_insert_labels
AFTER INSERT ON labels
FOR EACH ROW
EXECUTE FUNCTION replicate_labels_to_tags();
```

**Trigger para exclusões:**

```sql
CREATE TRIGGER after_delete_labels
AFTER DELETE ON labels
FOR EACH ROW
EXECUTE FUNCTION delete_labels_from_tags_and_taggings();
```

**Trigger para atualizações:**

```sql
CREATE TRIGGER after_update_labels
AFTER UPDATE ON labels
FOR EACH ROW
EXECUTE FUNCTION update_labels_to_tags();
```
**Trigger para inserções:**
```sql
CREATE TRIGGER after_insert_labels
AFTER INSERT ON labels
FOR EACH ROW
EXECUTE FUNCTION replicate_labels_to_tags();
```
**Trigger para exclusões:**
```sql
CREATE TRIGGER after_delete_labels
AFTER DELETE ON labels
FOR EACH ROW
EXECUTE FUNCTION delete_labels_from_tags_and_taggings();
```
**Trigger para atualizações:**
```sql
CREATE TRIGGER after_update_labels
AFTER UPDATE ON labels
FOR EACH ROW
EXECUTE FUNCTION update_labels_to_tags();
```

---

Expand Down

0 comments on commit 64d1965

Please sign in to comment.