Пример #1
0
        public async Task <int> CreateIndexAsync(NewIndex newIndex)
        {
            string query = $"CREATE INDEX ON :{newIndex.Label}({newIndex.Property})";
            int    count = 0;

            using (ISession session = this._driver.Session())
            {
                try
                {
                    await session.ReadTransactionAsync(async (tx) =>
                    {
                        IStatementResultCursor reader = await tx.RunAsync(query);
                        await reader.ConsumeAsync();
                        IResultSummary summary = await reader.SummaryAsync();
                        count = summary.Counters.IndexesAdded;
                    });
                }
                catch (Exception e)
                {
                    this._logger.LogError(e, $"Error creating index for label {newIndex.Label} on property {newIndex.Property}");
                }
                finally
                {
                    await session.CloseAsync();
                }
            }
            return(count);
        }
Пример #2
0
        public async Task <int> DropIndexAsync(string label, string propertyname)
        {
            string query = $"DROP INDEX ON :{label}({propertyname})";
            int    count = 0;

            using (ISession session = this._driver.Session())
            {
                try
                {
                    await session.ReadTransactionAsync(async (tx) =>
                    {
                        IStatementResultCursor reader = await tx.RunAsync(query);
                        await reader.ConsumeAsync();
                        IResultSummary summary = await reader.SummaryAsync();
                        count = summary.Counters.IndexesRemoved;
                    });
                }
                catch (Exception e)
                {
                    this._logger.LogError(e, $"Error dropping index for label {label} on property {propertyname}");
                }
                finally
                {
                    await session.CloseAsync();
                }
            }
            return(count);
        }
 public IResultSummary Consume()
 {
     return(_executor.RunSync(() => _cursor.ConsumeAsync()));
 }