コード例 #1
0
ファイル: Program.cs プロジェクト: GeertVL/DynamoDb.SQL
        private static void QueryByHashKey(string userId, AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT * FROM GameScores WHERE UserId = \"{0}\"", userId);

            Console.WriteLine("(AmazonDynamoDBClient) Running basic hash key query :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);
            Debug.Assert(response.Items.Count == 5);
            Debug.Assert(response.Items.TrueForAll(i => i["UserId"].S == userId));

            Console.WriteLine("(DynamoDBContext) Running basic hash key query :\n\t\t{0}", selectQuery);
            var gameScores = context.ExecQuery<GameScore>(selectQuery).ToArray();
            Debug.Assert(gameScores.Count() == 5);
            Debug.Assert(gameScores.All(gs => gs.UserId == userId));
        }
コード例 #2
0
        private static void QueryByHashKey(string userId, AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT * FROM GameScores WHERE UserId = \"{0}\"", userId);

            Console.WriteLine("(AmazonDynamoDBClient) Running basic hash key query :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);

            Debug.Assert(response.Items.Count == 5);
            Debug.Assert(response.Items.TrueForAll(i => i["UserId"].S == userId));

            Console.WriteLine("(DynamoDBContext) Running basic hash key query :\n\t\t{0}", selectQuery);
            var gameScores = context.ExecQuery <GameScore>(selectQuery).ToArray();

            Debug.Assert(gameScores.Count() == 5);
            Debug.Assert(gameScores.All(gs => gs.UserId == userId));
        }
コード例 #3
0
        private static void ThrottlingWithQueryPageSize(string userId, AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT * FROM GameScores WHERE UserId = \"{0}\" LIMIT 3 WITH (PageSize(1))", userId);

            Console.WriteLine("(AmazonDynamoDBClient) Running query with PageSize :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);

            Debug.Assert(response.Items.Count == 3);
            Debug.Assert(response.Items.TrueForAll(i => i["UserId"].S == userId));

            Console.WriteLine("(DynamoDBContext) Running query with PageSize :\n\t\t{0}", selectQuery);
            var gameScores = context.ExecQuery <GameScore>(selectQuery).ToArray();

            Debug.Assert(gameScores.Count() == 3);
            Debug.Assert(gameScores.All(gs => gs.UserId == userId));
        }
コード例 #4
0
        private static void QueryWithOrderAndLimit(string userId, AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT * FROM GameScores WHERE UserId = \"{0}\" ORDER ASC LIMIT 3", userId);

            Console.WriteLine("(AmazonDynamoDBClient) Running query with order and limit :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);

            Debug.Assert(response.Items.Count == 3);
            Debug.Assert(response.Items.TrueForAll(i => i["UserId"].S == userId));
            Debug.Assert(response.Items.TrueForAll(i => i["GameTitle"].S.CompareTo(MeteorBlasters) < 0));

            Console.WriteLine("(DynamoDBContext) Running query with order and limit :\n\t\t{0}", selectQuery);
            var gameScores = context.ExecQuery <GameScore>(selectQuery).ToArray();

            Debug.Assert(gameScores.Count() == 3);
            Debug.Assert(gameScores.All(gs => gs.UserId == userId));
            Debug.Assert(gameScores.All(gs => gs.GameTitle.CompareTo(MeteorBlasters) < 0));
        }
コード例 #5
0
        private static void QueryWithRangeKey(string userId, AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT * FROM GameScores WHERE UserId = \"{0}\" AND GameTitle BEGINS WITH \"A\"", userId);

            Console.WriteLine("(AmazonDynamoDBClient) Running query with range key :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);

            Debug.Assert(response.Items.Count == 2);
            Debug.Assert(response.Items.TrueForAll(i => i["UserId"].S == userId));
            Debug.Assert(response.Items.TrueForAll(i => i["GameTitle"].S.StartsWith("A")));

            Console.WriteLine("(DynamoDBContext) Running query with range key :\n\t\t{0}", selectQuery);

            var gameScores = context.ExecQuery <GameScore>(selectQuery).ToArray();

            Debug.Assert(gameScores.Count() == 2);
            Debug.Assert(gameScores.All(gs => gs.UserId == userId));
            Debug.Assert(gameScores.All(gs => gs.GameTitle.StartsWith("A")));
        }
コード例 #6
0
        private static void QueryWithLocalSecondaryIndexProjectedAttributes(string userId, AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT * FROM GameScores WHERE UserId = \"{0}\" AND TopScore >= 1000 WITH(Index(TopScoreIndex, false))", userId);

            Console.WriteLine("(AmazonDynamoDBClient) Running query with local secondary index (projected attributes) :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);

            Debug.Assert(response.Items.Count > 0);
            Debug.Assert(response.Items.TrueForAll(i => i["UserId"].S == userId));
            Debug.Assert(response.Items.TrueForAll(i => int.Parse(i["TopScore"].N) >= 1000));
            Debug.Assert(response.Items.TrueForAll(i => i.Count == 3 && !i.ContainsKey("TopScoreDateTime")));

            Console.WriteLine("(DynamoDBContext) Running query with local secondary index (projected attributes) :\n\t\t{0}", selectQuery);
            var gameScores = context.ExecQuery <GameScore>(selectQuery).ToArray();

            Debug.Assert(gameScores.Any());
            Debug.Assert(gameScores.All(gs => gs.UserId == userId));
            Debug.Assert(gameScores.All(gs => gs.TopScore >= 1000));
            Debug.Assert(gameScores.All(gs => gs.TopScoreDateTime == default(DateTime)));
        }
コード例 #7
0
        private static void QueryWithGlobalSecondaryIndexProjectedAttributes(AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT * FROM GameScores WHERE GameTitle = \"{0}\" AND TopScore >= 1000 WITH(Index(GameTitleIndex, false), NoConsistentRead)", StarshipX);

            Console.WriteLine("(AmazonDynamoDBClient) Running query with global secondary index (projected attributes) :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);

            Debug.Assert(response.Items.Count > 0);
            Debug.Assert(response.Items.TrueForAll(i => !string.IsNullOrWhiteSpace(i["UserId"].S)));
            Debug.Assert(response.Items.TrueForAll(i => i["GameTitle"].S == StarshipX));
            Debug.Assert(response.Items.TrueForAll(i => int.Parse(i["TopScore"].N) >= 1000));
            Debug.Assert(response.Items.TrueForAll(i => i.Count == 3 && !i.ContainsKey("TopScoreDateTime")));

            Console.WriteLine("(DynamoDBContext) Running query with global secondary index (projected attributes) :\n\t\t{0}", selectQuery);
            var gameScores = context.ExecQuery <GameScore>(selectQuery).ToArray();

            Debug.Assert(gameScores.Any());
            Debug.Assert(gameScores.All(gs => !string.IsNullOrWhiteSpace(gs.UserId)));
            Debug.Assert(gameScores.All(gs => gs.GameTitle == StarshipX));
            Debug.Assert(gameScores.All(gs => gs.TopScore >= 1000));
            Debug.Assert(gameScores.All(gs => gs.TopScoreDateTime == default(DateTime)));
        }
コード例 #8
0
        private static void SelectSpecificAttributes(string userId, AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT UserId, GameTitle, Wins FROM GameScores WHERE UserId = \"{0}\"", userId);

            Console.WriteLine("(AmazonDynamoDBClient) Running query with specific attributes :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);

            Debug.Assert(response.Items.Count == 5);
            Debug.Assert(response.Items.TrueForAll(i => i["UserId"].S == userId));
            Debug.Assert(response.Items.TrueForAll(i => i.Count() == 3));

            Console.WriteLine("(DynamoDBContext) Running query with specific attributes :\n\t\t{0}", selectQuery);
            var gameScores = context.ExecQuery <GameScore>(selectQuery).ToArray();

            Debug.Assert(gameScores.Count() == 5);
            Debug.Assert(gameScores.All(gs => gs.UserId == userId));
            Debug.Assert(gameScores.All(gs => !string.IsNullOrWhiteSpace(gs.GameTitle) &&
                                        gs.Wins > 0 &&
                                        gs.Losses == 0 &&
                                        gs.TopScore == 0 &&
                                        gs.TopScoreDateTime == default(DateTime)));
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: GeertVL/DynamoDb.SQL
        private static void QueryWithOrderAndLimit(string userId, AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT * FROM GameScores WHERE UserId = \"{0}\" ORDER ASC LIMIT 3", userId);

            Console.WriteLine("(AmazonDynamoDBClient) Running query with order and limit :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);
            Debug.Assert(response.Items.Count == 3);
            Debug.Assert(response.Items.TrueForAll(i => i["UserId"].S == userId));
            Debug.Assert(response.Items.TrueForAll(i => i["GameTitle"].S.CompareTo(MeteorBlasters) < 0));

            Console.WriteLine("(DynamoDBContext) Running query with order and limit :\n\t\t{0}", selectQuery);
            var gameScores = context.ExecQuery<GameScore>(selectQuery).ToArray();
            Debug.Assert(gameScores.Count() == 3);
            Debug.Assert(gameScores.All(gs => gs.UserId == userId));
            Debug.Assert(gameScores.All(gs => gs.GameTitle.CompareTo(MeteorBlasters) < 0));
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: GeertVL/DynamoDb.SQL
        private static void QueryWithRangeKey(string userId, AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT * FROM GameScores WHERE UserId = \"{0}\" AND GameTitle BEGINS WITH \"A\"", userId);

            Console.WriteLine("(AmazonDynamoDBClient) Running query with range key :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);
            Debug.Assert(response.Items.Count == 2);
            Debug.Assert(response.Items.TrueForAll(i => i["UserId"].S == userId));
            Debug.Assert(response.Items.TrueForAll(i => i["GameTitle"].S.StartsWith("A")));

            Console.WriteLine("(DynamoDBContext) Running query with range key :\n\t\t{0}", selectQuery);

            var gameScores = context.ExecQuery<GameScore>(selectQuery).ToArray();
            Debug.Assert(gameScores.Count() == 2);
            Debug.Assert(gameScores.All(gs => gs.UserId == userId));
            Debug.Assert(gameScores.All(gs => gs.GameTitle.StartsWith("A")));
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: GeertVL/DynamoDb.SQL
        private static void QueryWithGlobalSecondaryIndexProjectedAttributes(AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT * FROM GameScores WHERE GameTitle = \"{0}\" AND TopScore >= 1000 WITH(Index(GameTitleIndex, false), NoConsistentRead)", StarshipX);

            Console.WriteLine("(AmazonDynamoDBClient) Running query with global secondary index (projected attributes) :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);
            Debug.Assert(response.Items.Count > 0);
            Debug.Assert(response.Items.TrueForAll(i => !string.IsNullOrWhiteSpace(i["UserId"].S)));
            Debug.Assert(response.Items.TrueForAll(i => i["GameTitle"].S == StarshipX));
            Debug.Assert(response.Items.TrueForAll(i => int.Parse(i["TopScore"].N) >= 1000));
            Debug.Assert(response.Items.TrueForAll(i => i.Count == 3 && !i.ContainsKey("TopScoreDateTime")));

            Console.WriteLine("(DynamoDBContext) Running query with global secondary index (projected attributes) :\n\t\t{0}", selectQuery);
            var gameScores = context.ExecQuery<GameScore>(selectQuery).ToArray();
            Debug.Assert(gameScores.Any());
            Debug.Assert(gameScores.All(gs => !string.IsNullOrWhiteSpace(gs.UserId)));
            Debug.Assert(gameScores.All(gs => gs.GameTitle == StarshipX));
            Debug.Assert(gameScores.All(gs => gs.TopScore >= 1000));
            Debug.Assert(gameScores.All(gs => gs.TopScoreDateTime == default(DateTime)));
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: GeertVL/DynamoDb.SQL
        private static void QueryWithLocalSecondaryIndexProjectedAttributes(string userId, AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT * FROM GameScores WHERE UserId = \"{0}\" AND TopScore >= 1000 WITH(Index(TopScoreIndex, false))", userId);

            Console.WriteLine("(AmazonDynamoDBClient) Running query with local secondary index (projected attributes) :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);
            Debug.Assert(response.Items.Count > 0);
            Debug.Assert(response.Items.TrueForAll(i => i["UserId"].S == userId));
            Debug.Assert(response.Items.TrueForAll(i => int.Parse(i["TopScore"].N) >= 1000));
            Debug.Assert(response.Items.TrueForAll(i => i.Count == 3 && !i.ContainsKey("TopScoreDateTime")));

            Console.WriteLine("(DynamoDBContext) Running query with local secondary index (projected attributes) :\n\t\t{0}", selectQuery);
            var gameScores = context.ExecQuery<GameScore>(selectQuery).ToArray();
            Debug.Assert(gameScores.Any());
            Debug.Assert(gameScores.All(gs => gs.UserId == userId));
            Debug.Assert(gameScores.All(gs => gs.TopScore >= 1000));
            Debug.Assert(gameScores.All(gs => gs.TopScoreDateTime == default(DateTime)));
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: GeertVL/DynamoDb.SQL
        private static void SelectSpecificAttributes(string userId, AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT UserId, GameTitle, Wins FROM GameScores WHERE UserId = \"{0}\"", userId);

            Console.WriteLine("(AmazonDynamoDBClient) Running query with specific attributes :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);
            Debug.Assert(response.Items.Count == 5);
            Debug.Assert(response.Items.TrueForAll(i => i["UserId"].S == userId));
            Debug.Assert(response.Items.TrueForAll(i => i.Count() == 3));

            Console.WriteLine("(DynamoDBContext) Running query with specific attributes :\n\t\t{0}", selectQuery);
            var gameScores = context.ExecQuery<GameScore>(selectQuery).ToArray();
            Debug.Assert(gameScores.Count() == 5);
            Debug.Assert(gameScores.All(gs => gs.UserId == userId));
            Debug.Assert(gameScores.All(gs => !string.IsNullOrWhiteSpace(gs.GameTitle) &&
                                              gs.Wins > 0 &&
                                              gs.Losses == 0 &&
                                              gs.TopScore == 0 &&
                                              gs.TopScoreDateTime == default(DateTime)));
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: GeertVL/DynamoDb.SQL
        private static void ThrottlingWithQueryPageSize(string userId, AmazonDynamoDBClient client, DynamoDBContext context)
        {
            var selectQuery = string.Format("SELECT * FROM GameScores WHERE UserId = \"{0}\" LIMIT 3 WITH (PageSize(1))", userId);

            Console.WriteLine("(AmazonDynamoDBClient) Running query with PageSize :\n\t\t{0}", selectQuery);
            var response = client.Query(selectQuery);
            Debug.Assert(response.Items.Count == 3);
            Debug.Assert(response.Items.TrueForAll(i => i["UserId"].S == userId));

            Console.WriteLine("(DynamoDBContext) Running query with PageSize :\n\t\t{0}", selectQuery);
            var gameScores = context.ExecQuery<GameScore>(selectQuery).ToArray();
            Debug.Assert(gameScores.Count() == 3);
            Debug.Assert(gameScores.All(gs => gs.UserId == userId));
        }