Esempio n. 1
0
        private static async Task DeleteRoute()
        {
            string dbname = cliArgs[1];
            string cname  = cliArgs[2];
            string route  = cliArgs[3];

            cosmosClient = CosmosClientFactory.RegularClient();
            CosmosQueryUtil util = new CosmosQueryUtil(cosmosClient, config.IsVerbose());
            await util.SetCurrentDatabase(dbname);

            await util.SetCurrentContainer(cname);

            string sql = $"select c.id, c.pk from c where c.route = '{route}'";

            QueryResponse respObj = await util.ExecuteQuery(sql);

            string jstr    = respObj.ToJson();
            string outfile = "out/delete_route.json";
            await File.WriteAllTextAsync(outfile, jstr);

            Console.WriteLine($"file written: {outfile}");

            for (int i = 0; i < respObj.itemCount; i++)
            {
                dynamic         item = respObj.items[i];
                string          id   = item["id"];
                string          pk   = item["pk"];
                GenericDocument gd   = new GenericDocument(id, pk);
                Console.WriteLine($"deleting {gd.ToJson()}");
                ItemResponse <GenericDocument> resp = await util.DeleteGenericDocument(gd);

                Console.WriteLine($"resp, status: {resp.StatusCode} ru: {resp.RequestCharge}");
            }
        }
Esempio n. 2
0
        private static async Task ExecuteQueries()
        {
            string dbname = cliArgs[1];
            string cname  = cliArgs[2];
            string infile = cliArgs[3];

            cosmosClient = CosmosClientFactory.RegularClient();
            CosmosQueryUtil util = new CosmosQueryUtil(cosmosClient, config.IsVerbose());
            await util.SetCurrentDatabase(dbname);

            await util.SetCurrentContainer(cname);

            // Console.WriteLine("warming sdk client...");
            for (int i = 0; i < 2; i++)
            {
                await util.CountDocuments("");
            }

            foreach (string line in File.ReadLines(infile))
            {
                string[] tokens = line.Split("|");
                if (tokens.Length > 1)
                {
                    string qname = tokens[0].Trim();
                    string sql   = tokens[1].Trim();
                    if (qname.StartsWith("q"))
                    {
                        Console.WriteLine("");
                        Console.WriteLine("================================================================================");
                        Console.WriteLine($"executing qname: {qname}, db: {dbname}, cname: {cname}, sql: {sql}");
                        QueryResponse respObj = await util.ExecuteQuery(sql);

                        respObj.queryName = qname;
                        respObj.sql       = sql;
                        respObj.dbname    = dbname;
                        respObj.cname     = cname;
                        respObj.Finish();
                        Console.WriteLine(respObj.ToString());
                        string jstr = respObj.ToJson();
                        if (config.IsVerbose())
                        {
                            Console.WriteLine(jstr);
                        }
                        await File.WriteAllTextAsync(respObj.filename, jstr);

                        Console.WriteLine($"file written: {respObj.filename}");
                    }
                }
            }
        }
Esempio n. 3
0
        private static async Task CountDocuments()
        {
            string dbname = cliArgs[1];
            string cname  = cliArgs[2];

            cosmosClient = CosmosClientFactory.RegularClient();
            CosmosQueryUtil util = new CosmosQueryUtil(cosmosClient, config.IsVerbose());
            await util.SetCurrentDatabase(dbname);

            await util.SetCurrentContainer(cname);

            int count = (await util.CountDocuments("")).items[0];

            Console.WriteLine($"CountDocuments {dbname} {cname} -> {count}");
        }