Skip to content

Commit

Permalink
ext: support queries like insert/update/delete/etc
Browse files Browse the repository at this point in the history
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
  • Loading branch information
dotnwat committed Jan 6, 2017
1 parent f23d994 commit b6be643
Show file tree
Hide file tree
Showing 7 changed files with 29,893 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Makefile
@@ -1,5 +1,5 @@
MODULE_big = pg_zlog
OBJS = pg_zlog.o
OBJS = pg_zlog.o ruleutils_94.o ruleutils_95.o ruleutils_96.o
EXTENSION = pg_zlog
DATA = pg_zlog--0.1.sql

Expand All @@ -18,7 +18,7 @@ testdb:
= 'pg_zlog'/" testdb_data/postgresql.conf

testdbrun:
postgres -D testdb_data
postgres -D testdb_data -d 1

testdbinit:
echo 'CREATE EXTENSION pg_zlog;' | psql postgres
Expand Down
20 changes: 17 additions & 3 deletions pg_zlog--0.1.sql
Expand Up @@ -33,13 +33,19 @@ BEGIN
END;
$BODY$ LANGUAGE plpgsql;

CREATE FUNCTION pgzlog_apply_update(log_name text, query text, pos bigint)
CREATE FUNCTION pgzlog_start_update(log_name text)
RETURNS void
as $BODY$
BEGIN
PERFORM pg_advisory_xact_lock(29030, hashtext(log_name));
PERFORM pg_advisory_xact_lock(29030, hashtext(log_name));
SET LOCAL pg_zlog.enabled TO false;
END;
$BODY$ LANGUAGE 'plpgsql';

SET LOCAL pg_zlog.enabled TO false;
CREATE FUNCTION pgzlog_apply_update(log_name text, query text, pos bigint)
RETURNS void
as $BODY$
BEGIN

RAISE DEBUG 'Executing: %', query;

Expand All @@ -53,3 +59,11 @@ BEGIN
WHERE name = log_name;
END;
$BODY$ LANGUAGE 'plpgsql';

/*
* zlog_execute executes a query locally, by-passing the query logging logic.
*/
CREATE FUNCTION zlog_execute(INTERNAL)
RETURNS void
LANGUAGE C
AS 'MODULE_PATHNAME', $$zlog_execute$$;

0 comments on commit b6be643

Please sign in to comment.