Пример #1
0
        /// <summary>
        ///     Run any database query defined by the passed query parameter.
        /// </summary>
        public async Task RunQuery(string query)
        {
            using var session = DatabaseSession.StartSession(_driver, _appSettings.DatabaseName);
            Console.WriteLine(query);
            var cursor = await session.RunAsync(query);

            await cursor.ConsumeAsync();
        }
Пример #2
0
        /// <summary>
        ///     Find all nodes with label corresponding to the T type.
        /// </summary>
        /// <typeparam name="T">Type of the Model that will be searched in the database.</typeparam>
        public async Task <IEnumerable <T> > GetAllOfLabel <T>() where T : BaseModel
        {
            var modelName = typeof(T).Name;

            using var session = DatabaseSession.StartSession(_driver, _appSettings.DatabaseName);

            var cursor = await session.RunAsync($"MATCH (x:{modelName})\nRETURN x");

            var results = (await cursor.ToListAsync()).Map <T>();

            return(results);
        }
Пример #3
0
        /// <summary>
        ///     Create a new T model node.
        /// </summary>
        /// <param name="model">Model to add to the database.</param>
        /// <typeparam name="T">Type of the model that will be added.</typeparam>
        public async Task <T> Create <T>(T model) where T : BaseModel
        {
            var modelName = typeof(T).Name;

            using var session = DatabaseSession.StartSession(_driver, _appSettings.DatabaseName);

            model.Id = Guid.NewGuid().ToString();
            var key        = $"new{modelName}";
            var parameters = new Neo4jParameters().WithEntity(key, model);
            var query      = $@"
                CREATE (x:{modelName} ${key}) 
                RETURN x";

            Console.WriteLine(query);

            var cursor = await session.RunAsync(query, parameters);

            var result = await cursor.MapSingleAsync <T>();

            return(result);
        }