Sha256: 0cd60e00636d14eb61dce8cf8728e0d963c8d1ce021f956637fe62b6864b83db

Contents?: true

Size: 887 Bytes

Versions: 37

Compression:

Stored size: 887 Bytes

Contents

CREATE OR REPLACE FUNCTION get_stream_messages(
  _stream_name varchar,
  _position bigint DEFAULT 0,
  _batch_size bigint DEFAULT 1000,
  _condition varchar DEFAULT NULL
)
RETURNS SETOF message
AS $$
DECLARE
  command text;
BEGIN
  command := '
    SELECT
      id::varchar,
      stream_name::varchar,
      type::varchar,
      position::bigint,
      global_position::bigint,
      data::varchar,
      metadata::varchar,
      time::timestamp
    FROM
      messages
    WHERE
      stream_name = $1 AND
      position >= $2';

  if _condition is not null then
    command := command || ' AND
      %s';
    command := format(command, _condition);
  end if;

  command := command || '
    ORDER BY
      position ASC
    LIMIT
      $3';

  -- RAISE NOTICE '%', command;

  RETURN QUERY EXECUTE command USING _stream_name, _position, _batch_size;
END;
$$ LANGUAGE plpgsql
VOLATILE;

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
evt-message_store-postgres-database-1.1.0.2 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-1.1.0.1 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-1.1.0.0 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-1.0.0.0 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.11.0.0 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.10.1.3 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.10.1.2 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.10.1.1 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.10.1.0 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.10.0.1 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.10.0.0 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.9.0.1 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.9.0.0 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.8.0.0 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.7.1.1 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.7.1.0 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.7.0.0 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.6.0.0 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.5.0.0 database/functions/get-stream-messages.sql
evt-message_store-postgres-database-0.4.1.0 database/functions/get-stream-messages.sql