Exemplo n.º 1
0
        /// <summary>
        /// Creates a listener on the specified channel. When using a listener,
        /// it may be helpful to also turn on keepalive in the database connection
        /// string.
        /// </summary>
        /// <param name="channel">The channel to listen on.</param>
        /// <returns>An event listener for the specified channel.</returns>
        public async Task <PostgresEventListener> CreateListenerAsync(string channel)
        {
            var connection = await CreateConnectionAsync() as NpgsqlConnection;

            await connection.OpenAsync();

            var listener = new PostgresEventListener(connection);

            using (var command = new NpgsqlCommand($"LISTEN {Dialect.FormatIdentifier(channel)}", connection))
            {
                await command.ExecuteNonQueryAsync();
            }

            return(listener);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Writes the specified <paramref name="identifier"/> to the output stream.
        /// </summary>
        /// <param name="identifier">
        /// The <see cref="SqlIdentifier"/> to write to the output stream.
        /// </param>
        public void WriteIdentifier(SqlIdentifier identifier)
        {
            EnsureNotDisposed();
            if (identifier == null)
            {
                throw new ArgumentNullException(nameof(identifier));
            }

            for (int index = 0; index < identifier.Segments.Length; index++)
            {
                var segment = identifier.Segments[index];
                if (index > 0)
                {
                    WriteRaw(".");
                    WriteRaw(Dialect.FormatIdentifier(segment));
                }
                else
                {
                    Write(Dialect.FormatIdentifier(segment));
                }
            }
        }