/// <summary> /// Typically called from the Client Singleton using `Client.Instance.Table<T>` /// </summary> /// <param name="baseUrl">Api Endpoint (ex: "http://localhost:8000"), no trailing slash required.</param> /// <param name="authorization">Authorization Information.</param> /// <param name="options">Optional client configuration.</param> public Table(string baseUrl, ClientOptions options = null) { BaseUrl = baseUrl; if (options == null) { options = new ClientOptions(); } this.options = options; if (serializerSettings == null) { serializerSettings = StatelessClient.SerializerSettings(options); } var attr = Attribute.GetCustomAttribute(typeof(T), typeof(TableAttribute)); if (attr is TableAttribute tableAttr) { TableName = tableAttr.Name; } else { TableName = typeof(T).Name; } }
/// <summary> /// Perform a stored procedure call. /// </summary> /// <param name="procedureName">The function name to call</param> /// <param name="parameters">The parameters to pass to the function call</param> /// <returns></returns> public Task <BaseResponse> Rpc(string procedureName, Dictionary <string, object> parameters) { // Build Uri var builder = new UriBuilder($"{BaseUrl}/rpc/{procedureName}"); var canonicalUri = builder.Uri.ToString(); var serializerSettings = StatelessClient.SerializerSettings(options); // Prepare parameters var data = JsonConvert.DeserializeObject <Dictionary <string, string> >(JsonConvert.SerializeObject(parameters, serializerSettings)); // Prepare headers var headers = Helpers.PrepareRequestHeaders(HttpMethod.Post, new Dictionary <string, string>(options.Headers), options); // Send request var request = Helpers.MakeRequest(HttpMethod.Post, canonicalUri, serializerSettings, data, headers); return(request); }
/// <summary> /// Returns a Table Query Builder instance for a defined model - representative of `USE $TABLE` /// </summary> /// <typeparam name="T">Custom Model derived from `BaseModel`</typeparam> /// <returns></returns> public Table <T> Table <T>() where T : BaseModel, new() => new Table <T>(BaseUrl, options, StatelessClient.SerializerSettings(options));