Exemple #1
0
        public IUser GetByUsername(string username)
        {
            var key = db.Get(String.Format(keyPattern, username)).ToString();

            key = key.Replace("\"", "");
            return(db.GetJson <User>(key));
        }
        public static T GetJson <T>(this ICouchbaseClient client, string key) where T : class
        {
            var json = client.Get <string>(key);

            json = DocHelper.InsertId(json, key);
            return(json == null ? null : JsonConvert.DeserializeObject <T>(json));
        }
        private IEnumerable <IProduct> Get(IEnumerable <string> keys)
        {
            if (!keys.Any())
            {
                yield break;
            }

            var _results = db.Get(keys).Where(o => o.Value != null).Select(o => o.Value);

            if (!_results.Any())
            {
                yield break;
            }

            foreach (var o in _results)
            {
                yield return(JsonConvert.DeserializeObject <Product>(o.ToString()));
            }
        }
        public static T TransformRow(JsonReader reader, ICouchbaseClient client, bool shouldLookupById)
        {
            if (shouldLookupById)
            {
                var key  = Json.ParseValue(reader, "id") as string;
                var json = client.Get <string>(key);
                if (string.IsNullOrEmpty(json))
                {
                    return(default(T));
                }

                var jsonWithId = DocHelper.InsertId(json, key);                //_id is omitted from the Json return by Get
                return(JsonConvert.DeserializeObject <T>(jsonWithId));
            }
            else
            {
                var jObject = Json.ParseValue(reader, "value");
                return(JsonConvert.DeserializeObject <T>(jObject));
            }
        }
        public static T GetJson <T>(this ICouchbaseClient client, string key) where T : class
        {
            var json = client.Get <string>(key);

            return(json == null || json == Null ? null : DeserializeObject <T>(key, json));
        }