
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
github.com/120dev/elasticsearch-postgres
Project in Go + SQL to create an ElasticSearch index from PostgreSQL database.
This procedure is for a Linux operating system.
The following dependencies needs to be previously installed :
Two ways to start listening:
Nothing changes in terms of triggers
docker pull postgres
docker run --name abcd -e POSTGRES_PASSWORD=abcd -d postgres
docker pull thajeztah/pgadmin4
docker run --restart=always -p 5050:5050 thajeztah/pgadmin4
docker pull elasticsearch
docker run --restart=always -d -p 9200:9200 -p 9300:9300 -it -h elasticsearch --name elasticsearch elasticsearch
PUT http://localhost:9200/<INDEX_NAME>
{
"settings" : {
"index" : {
"number_of_shards" : 5,
"number_of_replicas" : 2
}
}
}
OR :
curl -XPUT 'http://localhost:9200/<INDEX_NAME>' -d '{"settings" : {"number_of_shards" : 5, "number_of_replicas" : 2}}'
CREATE OR REPLACE FUNCTION public.notify_event()
RETURNS trigger
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$
DECLARE
data json;
notification json;
id integer;
BEGIN
-- Convert the old or new row to JSON, based on the kind of action.
-- Action = DELETE? -> OLD row
-- Action = INSERT or UPDATE? -> NEW row
IF (TG_OP = 'DELETE') THEN
data = row_to_json(OLD);
id = OLD.id;
ELSE
data = row_to_json(NEW);
id = NEW.id;
END IF;
-- Contruct the notification as a JSON string.
notification = json_build_object(
'table',TG_TABLE_NAME,
'action', TG_OP,
'id', id,
'data', data);
-- Execute pg_notify(channel, notification)
PERFORM pg_notify('events',notification::text);
-- Result is ignored since this is an AFTER trigger
RETURN NULL;
END;
$BODY$;
CREATE TRIGGER products_notify_event
AFTER INSERT OR DELETE OR UPDATE
ON public.users
FOR EACH ROW
EXECUTE PROCEDURE public.notify_event();
https://go.dev/doc/install
go mod init PostGresToES
go mod tidy
go build PostGresToES.go && chmod +x ./PostGresToES
or go build PostGresToES_ApiGateway.go && chmod +x ./PostGresToES_ApiGateway
./PostGresToES or ./PostGresToES_ApiGateway
And wait, all events are logged.
You can render UML diagrams using Mermaid. For example, this will produce a sequence diagram:
sequenceDiagram
PostgreSQL ->> Trigger: Event crud in Json
Trigger ->> Go: Read and set ES _id
Go ->> ES: Post Json to ES
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.