public DynamoDBSink(IFormatProvider formatProvider, string tableName) :base(1000, TimeSpan.FromSeconds(15)) { _formatProvider = formatProvider; _tableName = tableName; AmazonDynamoDbConfig = new AmazonDynamoDBConfig(); OperationConfig = new DynamoDBOperationConfig {OverrideTableName = tableName}; }
/// <summary> /// Loads an object from DynamoDB for the given key and using the given config. /// The keyObject is a partially-specified instance, where the /// hash/range properties are equal to the key of the item you /// want to load. /// /// Passed-in config overrides DynamoDBContextConfig on the context. /// Type must be marked up with DynamoDBTableAttribute and at least /// one public field/property with DynamoDBHashKeyAttribute. /// </summary> /// <typeparam name="T">Type to populate.</typeparam> /// <param name="keyObject">Key object defining the the target item.</param> /// <param name="operationConfig">Overriding configuration.</param> /// <returns> /// Object of type T, populated with properties of item loaded from DynamoDB. /// </returns> public T Load <T>(T keyObject, DynamoDBOperationConfig operationConfig) { return(LoadHelper <T>(keyObject, operationConfig, false)); }
/// <summary> /// Deserializes a document to an instance of type T. /// </summary> /// <typeparam name="T">Type to populate.</typeparam> /// <param name="document">Document with properties to use.</param> /// <param name="operationConfig">Config object which can be used to override the table used.</param> /// <returns> /// Object of type T, populated with properties from the document. /// </returns> public T FromDocument <T>(Document document, DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, Config); return(FromDocumentHelper <T>(document, flatConfig)); }
/// <summary> /// Loads an object from DynamoDB for the given hash primary key and using the given config. /// /// Passed-in config overrides DynamoDBContextConfig on the context. /// Type must be marked up with DynamoDBTableAttribute and at least /// one public field/property with DynamoDBHashKeyAttribute. /// </summary> /// <typeparam name="T">Type to populate.</typeparam> /// <param name="hashKey">Hash key element of the target item.</param> /// <param name="operationConfig">Overriding configuration.</param> /// <returns> /// Object of type T, populated with properties of item loaded from DynamoDB. /// </returns> public T Load <T>(object hashKey, DynamoDBOperationConfig operationConfig) { return(Load <T>(hashKey, null, operationConfig)); }
/// <summary> /// Saves an object to DynamoDB using passed-in configs. /// /// Passed-in config overrides DynamoDBContextConfig on the context. /// Type must be marked up with DynamoDBTableAttribute and at least /// one public field/property with DynamoDBHashKeyAttribute. /// </summary> /// <typeparam name="T">Type to save as.</typeparam> /// <param name="value">Object to save.</param> /// <param name="operationConfig">Overriding configuration.</param> public void Save <T>(T value, DynamoDBOperationConfig operationConfig) { SaveHelper <T>(value, operationConfig, false); }
/// <summary> /// Executes a Query operation against DynamoDB, finding items /// that match the specified hash primary key. /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="hashKeyValue">Hash key of the items to query.</param> /// <param name="operationConfig">Config object which can be used to override the table used.</param> /// <returns>Lazy-loaded collection of results.</returns> public IEnumerable <T> Query <T>(object hashKeyValue, DynamoDBOperationConfig operationConfig) { var query = ConvertQueryByValue <T>(hashKeyValue, null, operationConfig); return(FromSearch <T>(query)); }
/// <summary> /// Deletes an item in DynamoDB corresponding to a given hash primary key. /// /// No version check is done prior to delete. /// Type must be marked up with DynamoDBTableAttribute and at least /// one public field/property with DynamoDBHashKeyAttribute. /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="hashKey">Hash key element of the object to delete.</param> /// <param name="operationConfig">Config object which can be used to override that table used.</param> public void Delete <T>(object hashKey, DynamoDBOperationConfig operationConfig) { Delete <T>(hashKey, null, operationConfig); }
/// <summary> /// Deletes an item in DynamoDB corresponding to a given hash-and-range primary key. /// /// No version check is done prior to delete. /// Type must be marked up with DynamoDBTableAttribute and at least /// one public field/property with DynamoDBHashKeyAttribute. /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="hashKey">Hash key element of the object to delete.</param> /// <param name="rangeKey">Range key element of the object to delete.</param> /// <param name="operationConfig">Config object which can be used to override that table used.</param> internal void Delete <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig) { DynamoDBAsyncExecutor.IsMainThread("DeleteAsync"); DeleteHelper <T>(hashKey, rangeKey, operationConfig, false); }
/// <summary> /// Initiates the asynchronous execution of the Delete operation. /// <seealso cref="Amazon.DynamoDBv2.DataModel.DynamoDBContext.Delete"/> /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="hashKey">Hash key element of the object to delete.</param> /// <param name="rangeKey">Range key element of the object to delete.</param> /// <param name="operationConfig">Config object which can be used to override that table used.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndDelete /// operation.</returns> public IAsyncResult BeginDelete <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, AsyncCallback callback, object state) { return(DynamoDBAsyncExecutor.BeginOperation(() => { DeleteHelper <T>(hashKey, rangeKey, operationConfig, true); return null; }, callback, state)); }
/// <summary> /// Initiates the asynchronous execution of the Load operation. /// <seealso cref="Amazon.DynamoDBv2.DataModel.DynamoDBContext.Load"/> /// </summary> /// <typeparam name="T">Type to populate.</typeparam> /// <param name="keyObject">Key of the target item.</param> /// <param name="operationConfig">Overriding configuration.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndLoad /// operation.</returns> public IAsyncResult BeginLoad <T>(T keyObject, DynamoDBOperationConfig operationConfig, AsyncCallback callback, object state) { return(DynamoDBAsyncExecutor.BeginOperation(() => LoadHelper <T>(keyObject, operationConfig, true), callback, state)); }
/// <summary> /// Saves an object to DynamoDB using passed-in configs. /// /// Passed-in config overrides DynamoDBContextConfig on the context. /// Type must be marked up with DynamoDBTableAttribute and at least /// one public field/property with DynamoDBHashKeyAttribute. /// </summary> /// <typeparam name="T">Type to save as.</typeparam> /// <param name="value">Object to save.</param> /// <param name="operationConfig">Overriding configuration.</param> public void Save <T>(T value, DynamoDBOperationConfig operationConfig = null) { SaveHelper <T>(value, operationConfig); }
/// <summary> /// Loads an object from DynamoDB for the given hash primary key and using the given config. /// /// Passed-in config overrides DynamoDBContextConfig on the context. /// Type must be marked up with DynamoDBTableAttribute and at least /// one public field/property with DynamoDBHashKeyAttribute. /// </summary> /// <typeparam name="T">Type to populate.</typeparam> /// <param name="hashKey">Hash key element of the target item.</param> /// <param name="operationConfig">Overriding configuration.</param> /// <returns> /// Object of type T, populated with properties of item loaded from DynamoDB. /// </returns> internal T Load <T>(object hashKey, DynamoDBOperationConfig operationConfig) { DynamoDBAsyncExecutor.IsMainThread("LoadAsync"); return(Load <T>(hashKey, null, operationConfig)); }
/// <summary> /// Executes a Query operation against DynamoDB, finding items /// that match the specified range element condition for a hash-and-range primary key. /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="hashKeyValue">Hash key of the items to query.</param> /// <param name="op">Operation of the condition.</param> /// <param name="values"> /// Value(s) of the condition. /// For all operations except QueryOperator.Between, values should be one value. /// For QueryOperator.Between, values should be two values. /// </param> /// <param name="operationConfig">Config object which can be used to override the table used.</param> /// <returns>Lazy-loaded collection of results.</returns> internal IEnumerable <T> Query <T>(object hashKeyValue, QueryOperator op, IEnumerable <object> values, DynamoDBOperationConfig operationConfig) { DynamoDBAsyncExecutor.IsMainThread("QueryAsync"); if (values == null) { throw new ArgumentNullException("values"); } var query = ConvertQueryByValue <T>(hashKeyValue, op, values, operationConfig); return(FromSearch <T>(query)); }
/// <summary> /// Saves an object to DynamoDB using passed-in configs. /// /// Passed-in config overrides DynamoDBContextConfig on the context. /// Type must be marked up with DynamoDBTableAttribute and at least /// one public field/property with DynamoDBHashKeyAttribute. /// </summary> /// <typeparam name="T">Type to save as.</typeparam> /// <param name="value">Object to save.</param> /// <param name="operationConfig">Overriding configuration.</param> internal void Save <T>(T value, DynamoDBOperationConfig operationConfig) { DynamoDBAsyncExecutor.IsMainThread("SaveAsync"); SaveHelper <T>(value, operationConfig, false); }
public DynamoDBFlatConfig(DynamoDBOperationConfig operationConfig, DynamoDBContextConfig contextConfig) { if (operationConfig == null) operationConfig = _emptyOperationConfig; if (contextConfig == null) contextConfig = _emptyContextConfig; bool consistentRead = operationConfig.ConsistentRead ?? contextConfig.ConsistentRead ?? false; bool skipVersionCheck = operationConfig.SkipVersionCheck ?? contextConfig.SkipVersionCheck ?? false; bool ignoreNullValues = operationConfig.IgnoreNullValues ?? contextConfig.IgnoreNullValues ?? false; string overrideTableName = !string.IsNullOrEmpty(operationConfig.OverrideTableName) ? operationConfig.OverrideTableName : string.Empty; string tableNamePrefix = !string.IsNullOrEmpty(operationConfig.TableNamePrefix) ? operationConfig.TableNamePrefix : !string.IsNullOrEmpty(contextConfig.TableNamePrefix) ? contextConfig.TableNamePrefix : string.Empty; bool backwardQuery = operationConfig.BackwardQuery ?? false; string indexName = !string.IsNullOrEmpty(operationConfig.IndexName) ? operationConfig.IndexName : string.Empty; ConsistentRead = consistentRead; SkipVersionCheck = skipVersionCheck; IgnoreNullValues = ignoreNullValues; OverrideTableName = overrideTableName; TableNamePrefix = tableNamePrefix; BackwardQuery = backwardQuery; IndexName = indexName; }
public ContactPage() { this.SetBinding(ContentPage.TitleProperty, "FirstName"); NavigationPage.SetHasNavigationBar(this, true); var firstNameLabel = new Label { Text = "First Name" }; var firstNameEntry = new DoneEntry { Keyboard = Keyboard.Text }; firstNameEntry.SetBinding(Entry.TextProperty, "FirstName"); var lastNameLabel = new Label { Text = "Last Name" }; var lastNameEntry = new DoneEntry { Keyboard = Keyboard.Text }; lastNameEntry.SetBinding(Entry.TextProperty, "LastName"); var homePhoneNumberLabel = new Label { Text = "Home Phone" }; var homePhoneNumberEntry = new DoneEntry { Keyboard = Keyboard.Telephone }; homePhoneNumberEntry.SetBinding(Entry.TextProperty, "HomePhoneNumber"); var workPhoneNumberLabel = new Label { Text = "Work Phone" }; var workPhoneNumberEntry = new DoneEntry { Keyboard = Keyboard.Telephone }; workPhoneNumberEntry.SetBinding(Entry.TextProperty, "WorkPhoneNumber"); var mobileNumberLabel = new Label { Text = "Mobile Number" }; var mobileNumberEntry = new DoneEntry { Keyboard = Keyboard.Telephone }; mobileNumberEntry.SetBinding(Entry.TextProperty, "MobileNumber"); var emailLabel = new Label { Text = "Email" }; var emailEntry = new DoneEntry { Keyboard = Keyboard.Email }; emailEntry.SetBinding(Entry.TextProperty, "EmailAddress"); var saveButton = new Button { Text = "Save"}; saveButton.Clicked += async (sender, e) => { var contact = (Contact)BindingContext; var id = await AmazonUtils.Credentials.GetIdentityIdAsync(); DynamoDBOperationConfig config = new DynamoDBOperationConfig { IgnoreNullValues = false }; if (string.IsNullOrEmpty(contact.UserId)) { var userId = Guid.NewGuid().ToString(); contact.Id = id; contact.UserId = userId; } await AmazonUtils.DDBContext.SaveAsync<Contact>(contact, config); Navigation.PopAsync(); }; var deleteButton = new Button { Text = "Delete", BorderColor = Color.Red, BorderRadius = 2 }; deleteButton.Clicked += async (sender, e) => { var contact = (Contact)BindingContext; if (!string.IsNullOrEmpty(contact.UserId)) { contact.Id = await AmazonUtils.Credentials.GetIdentityIdAsync(); await AmazonUtils.DDBContext.DeleteAsync<Contact>(contact); } Navigation.PopAsync(); }; var cancelButton = new Button { Text = "Cancel", BorderColor = Color.Gray, BorderRadius = 2 }; cancelButton.Clicked += (sender, e) => { Navigation.PopAsync(); }; Content = new ScrollView { Content = new StackLayout { VerticalOptions = LayoutOptions.StartAndExpand, Padding = new Thickness(20), Children = { firstNameLabel, firstNameEntry, lastNameLabel, lastNameEntry, homePhoneNumberLabel, homePhoneNumberEntry, workPhoneNumberLabel, workPhoneNumberEntry, mobileNumberLabel, mobileNumberEntry, emailLabel, emailEntry, saveButton, cancelButton,deleteButton } } }; }
/// <summary> /// Initiates the asynchronous execution of the Save operation. /// <seealso cref="Amazon.DynamoDBv2.DataModel.DynamoDBContext.Save"/> /// </summary> /// <typeparam name="T">Type to save as.</typeparam> /// <param name="value">Object to save.</param> /// <param name="operationConfig">Overriding configuration.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndSave /// operation.</returns> public IAsyncResult BeginSave <T>(T value, DynamoDBOperationConfig operationConfig, AsyncCallback callback, object state) { return(DynamoDBAsyncExecutor.BeginOperation(() => { SaveHelper <T>(value, operationConfig, true); return null; }, callback, state)); }
public static void RunDataModelSample(DynamoDBContext context) { Console.WriteLine("Creating actors"); Actor christianBale = new Actor { Name = "Christian Bale", Bio = "Christian Charles Philip Bale is an excellent horseman and an avid reader.", BirthDate = new DateTime(1974, 1, 30), Address = new Address { City = "Los Angeles", Country = "USA" }, HeightInMeters = 1.83f, Version= 1 }; Actor michaelCaine = new Actor { Name = "Michael Caine", Bio = "Maurice Joseph Micklewhite is an English actor, better known as Michael Caine", BirthDate = new DateTime(1933, 3, 14), Address = new Address { City = "London", Country = "England" }, HeightInMeters = 1.88f, Version = 1 }; Console.WriteLine("Creating movie"); Movie darkKnight = new Movie { Title = "The Dark Knight", ReleaseDate = new DateTime(2008, 7, 18), Genres = new List<string> { "Action", "Crime", "Drama" }, ActorNames = new List<string> { christianBale.Name, michaelCaine.Name }, Version = 1 }; Console.WriteLine("Saving actors and movie"); DynamoDBOperationConfig config = new DynamoDBOperationConfig(); config.SkipVersionCheck = true; context.Save<Actor>(michaelCaine,config); context.Save<Actor>(christianBale,config); context.Save<Movie>(darkKnight, config); Console.WriteLine("Creating and saving new actor"); Actor maggieGyllenhaal = new Actor { Name = "Maggie Gyllenhaal", BirthDate = new DateTime(1977, 11, 16), Bio = "Maggie Gyllenhaal studied briefly at the Royal Academy of Dramatic Arts in London.", Address = new Address { City = "New York City", Country = "USA" }, HeightInMeters = 1.75f, Version = 1 }; context.Save<Actor>(maggieGyllenhaal, config); Console.WriteLine(); Console.WriteLine("Loading existing movie"); Movie existingMovie = context.Load<Movie>("The Dark Knight", new DateTime(2008, 7, 18)); Console.WriteLine(existingMovie.ToString()); Console.WriteLine(); Console.WriteLine("Loading nonexistent movie"); Movie nonexistentMovie = context.Load<Movie>("The Dark Knight", new DateTime(2008, 7, 19)); Console.WriteLine("Movie is null : " + (nonexistentMovie == null)); Console.WriteLine("Updating movie and saving"); existingMovie.ActorNames.Add(maggieGyllenhaal.Name); existingMovie.Genres.Add("Thriller"); context.Save<Movie>(existingMovie,config); Console.WriteLine("Adding movie with same hash key but different range key"); Movie darkKnight89 = new Movie { Title = "The Dark Knight", Genres = new List<string> { "Drama" }, ReleaseDate = new DateTime(1989, 2, 23), ActorNames = new List<string> { "Juan Diego", "Fernando Guillén", "Manuel de Blas" }, Version=1 }; context.Save<Movie>(darkKnight89, config); IEnumerable<Movie> movieQueryResults; Console.WriteLine(); Console.WriteLine("Running query 1, expecting 1 result"); movieQueryResults = context.Query<Movie>("The Dark Knight", QueryOperator.GreaterThan, new DateTime(1995, 1, 1)); foreach (var result in movieQueryResults) Console.WriteLine(result.ToString()); Console.WriteLine(); Console.WriteLine("Running query 2, expecting 2 results"); movieQueryResults = context.Query<Movie>("The Dark Knight", QueryOperator.Between, new DateTime(1970, 1, 1), new DateTime(2011, 1, 1)); foreach (var result in movieQueryResults) Console.WriteLine(result.ToString()); IEnumerable<Actor> actorScanResults; Console.WriteLine(); Console.WriteLine("Running scan 1, expecting 2 results"); actorScanResults = context.Scan<Actor>( new ScanCondition("HeightInMeters", ScanOperator.LessThan, 1.85f)); foreach (var result in actorScanResults) Console.WriteLine(result.ToString()); Console.WriteLine(); Console.WriteLine("Running scan 2, expecting 1 result"); Address scanAddress = new Address { City = "New York City", Country = "USA" }; actorScanResults = context.Scan<Actor>( new ScanCondition("Address", ScanOperator.Equal, scanAddress)); foreach (var result in actorScanResults) Console.WriteLine(result.ToString()); }
private ContextSearch ConvertScan <T>(IEnumerable <ScanCondition> conditions, DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, this.Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig <T>(flatConfig); ScanFilter filter = ComposeScanFilter(conditions, storageConfig, flatConfig); Table table = GetTargetTable(storageConfig, flatConfig); var scanConfig = new ScanOperationConfig { AttributesToGet = storageConfig.AttributesToGet, Select = SelectValues.SpecificAttributes, Filter = filter, ConditionalOperator = flatConfig.ConditionalOperator, IndexName = flatConfig.IndexName }; Search scan = table.Scan(scanConfig); return(new ContextSearch(scan, flatConfig)); }
/// <summary> /// Deletes an item in DynamoDB corresponding to a given hash-and-range primary key. /// /// No version check is done prior to delete. /// Type must be marked up with DynamoDBTableAttribute and at least /// one public field/property with DynamoDBHashKeyAttribute. /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="hashKey">Hash key element of the object to delete.</param> /// <param name="rangeKey">Range key element of the object to delete.</param> /// <param name="operationConfig">Config object which can be used to override that table used.</param> public void Delete <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig) { DeleteHelper <T>(hashKey, rangeKey, operationConfig, false); }
/// <summary> /// Initiates the asynchronous execution of the Load operation. /// <seealso cref="Amazon.DynamoDBv2.DataModel.DynamoDBContext.Load"/> /// </summary> /// <typeparam name="T">Type to populate.</typeparam> /// <param name="keyObject">Key of the target item.</param> /// <param name="operationConfig">Overriding configuration.</param> /// <param name="cancellationToken">Token which can be used to cancel the task.</param> /// <returns>A Task that can be used to poll or wait for results, or both.</returns> public Task <T> LoadAsync <T>(T keyObject, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default(CancellationToken)) { return(LoadHelperAsync(keyObject, operationConfig, cancellationToken)); }
/// <summary> /// Executes a Query operation against DynamoDB, finding items /// that match the specified range element condition for a hash-and-range primary key. /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="hashKeyValue">Hash key of the items to query.</param> /// <param name="op">Operation of the condition.</param> /// <param name="values"> /// Value(s) of the condition. /// For all operations except QueryOperator.Between, values should be one value. /// For QueryOperator.Between, values should be two values. /// </param> /// <param name="operationConfig">Config object which can be used to override the table used.</param> /// <returns>Lazy-loaded collection of results.</returns> public IEnumerable <T> Query <T>(object hashKeyValue, QueryOperator op, IEnumerable <object> values, DynamoDBOperationConfig operationConfig) { if (values == null) { throw new ArgumentNullException("values"); } var query = ConvertQueryByValue <T>(hashKeyValue, op, values, operationConfig); return(FromSearch <T>(query)); }
/// <summary> /// Initiates the asynchronous execution of the Delete operation. /// <seealso cref="Amazon.DynamoDBv2.DataModel.DynamoDBContext.Delete"/> /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="hashKey">Hash key element of the object to delete.</param> /// <param name="rangeKey">Range key element of the object to delete.</param> /// <param name="operationConfig">Config object which can be used to override that table used.</param> /// <param name="cancellationToken">Token which can be used to cancel the task.</param> /// <returns>A Task that can be used to poll or wait for results, or both.</returns> public Task DeleteAsync <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default(CancellationToken)) { return(DeleteHelperAsync <T>(hashKey, rangeKey, operationConfig, cancellationToken)); }
/// <summary> /// Retrieves the target table for the specified type /// </summary> /// <typeparam name="T">Type to retrieve table for</typeparam> /// <returns>Table object</returns> public Table GetTargetTable <T>(DynamoDBOperationConfig operationConfig) { return(GetTargetTableInternal <T>(operationConfig)); }
/// <summary> /// Configures an async Scan operation against DynamoDB, finding items /// that match the specified conditions. /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="conditions"> /// Conditions that the results should meet. /// </param> /// <param name="operationConfig">Config object which can be used to override that table used.</param> /// <returns>AsyncSearch which can be used to retrieve DynamoDB data.</returns> public AsyncSearch <T> ScanAsync <T>(IEnumerable <ScanCondition> conditions, DynamoDBOperationConfig operationConfig = null) { var scan = ConvertScan <T>(conditions, operationConfig); return(FromSearchAsync <T>(scan)); }
/// <summary> /// Creates a strongly-typed BatchWrite object, allowing /// a batch-write operation against DynamoDB. /// </summary> /// <typeparam name="T">Type of objects to write</typeparam> /// <param name="operationConfig">Config object which can be used to override that table used.</param> /// <returns>Empty strongly-typed BatchWrite object</returns> public BatchWrite <T> CreateBatchWrite <T>(DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config); return(new BatchWrite <T>(this, config)); }
/// <summary> /// Configures an async Query operation against DynamoDB, finding items /// that match the specified hash primary key. /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="hashKeyValue">Hash key of the items to query.</param> /// <param name="operationConfig">Config object which can be used to override the table used.</param> /// <returns>AsyncSearch which can be used to retrieve DynamoDB data.</returns> public AsyncSearch <T> QueryAsync <T>(object hashKeyValue, DynamoDBOperationConfig operationConfig = null) { var query = ConvertQueryByValue <T>(hashKeyValue, null, operationConfig); return(FromSearchAsync <T>(query)); }
/// <summary> /// Loads an object from DynamoDB for the given hash-and-range primary key and using the given config. /// /// Passed-in config overrides DynamoDBContextConfig on the context. /// Type must be marked up with DynamoDBTableAttribute and at least /// one public field/property with DynamoDBHashKeyAttribute. /// </summary> /// <typeparam name="T">Type to populate.</typeparam> /// <param name="hashKey">Hash key element of the target item.</param> /// <param name="rangeKey">Range key element of the target item.</param> /// <param name="operationConfig">Overriding configuration.</param> /// <returns> /// Object of type T, populated with properties of item loaded from DynamoDB. /// </returns> public T Load <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig) { return(LoadHelper <T>(hashKey, rangeKey, operationConfig, false)); }
/// <summary> /// Initiates the asynchronous execution of the Save operation. /// <seealso cref="Amazon.DynamoDBv2.DataModel.DynamoDBContext.Save"/> /// </summary> /// <typeparam name="T">Type to save as.</typeparam> /// <param name="value">Object to save.</param> /// <param name="operationConfig">Overriding configuration.</param> /// <param name="cancellationToken">Token which can be used to cancel the task.</param> /// <returns>A Task that can be used to poll or wait for results, or both.</returns> public Task SaveAsync <T>(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default(CancellationToken)) { return(SaveHelperAsync(value, operationConfig, cancellationToken)); }
/// <summary> /// Deletes an item in DynamoDB corresponding to given object. /// /// Passed-in config overrides DynamoDBContextConfig on the context. /// If SkipVersionCheck=false, will check version of object before deleting. /// Type must be marked up with DynamoDBTableAttribute and at least /// one public field/property with DynamoDBHashKeyAttribute. /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="value">Object to delete.</param> /// <param name="operationConfig">Overriding configuration.</param> public void Delete <T>(T value, DynamoDBOperationConfig operationConfig) { DeleteHelper <T>(value, operationConfig, false); }
/// <summary> /// Initiates the asynchronous execution of the Load operation. /// <seealso cref="Amazon.DynamoDBv2.DataModel.DynamoDBContext.Load"/> /// </summary> /// <typeparam name="T">Type to populate.</typeparam> /// <param name="hashKey">Hash key element of the target item.</param> /// <param name="operationConfig">Overriding configuration.</param> /// <param name="cancellationToken">Token which can be used to cancel the task.</param> /// <returns>A Task that can be used to poll or wait for results, or both.</returns> public Task <T> LoadAsync <T>(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default(CancellationToken)) { return(LoadHelperAsync <T>(hashKey, null, operationConfig, cancellationToken)); }
private Search ConvertQueryByValue <T>(object hashKeyValue, QueryOperator op, IEnumerable <object> values, DynamoDBOperationConfig operationConfig) { ItemStorageConfig storageConfig = ItemStorageConfigCache.GetConfig <T>(); List <QueryCondition> conditions = CreateQueryConditions(operationConfig, op, values, storageConfig); Search query = ConvertQueryByValue <T>(hashKeyValue, conditions, operationConfig, storageConfig); return(query); }
private Search ConvertQueryByValue <T>(object hashKeyValue, IEnumerable <QueryCondition> conditions, DynamoDBOperationConfig operationConfig, ItemStorageConfig storageConfig = null) { if (storageConfig == null) { storageConfig = ItemStorageConfigCache.GetConfig <T>(); } List <string> indexNames; DynamoDBFlatConfig currentConfig = new DynamoDBFlatConfig(operationConfig, this.config); QueryFilter filter = ComposeQueryFilter(currentConfig, hashKeyValue, conditions, storageConfig, out indexNames); return(ConvertQueryHelper <T>(currentConfig, storageConfig, filter, indexNames)); }
public DynamoDBFlatConfig(DynamoDBOperationConfig operationConfig, DynamoDBContextConfig contextConfig) { if (operationConfig == null) operationConfig = _emptyOperationConfig; if (contextConfig == null) contextConfig = _emptyContextConfig; bool consistentRead = operationConfig.ConsistentRead ?? contextConfig.ConsistentRead ?? false; bool skipVersionCheck = operationConfig.SkipVersionCheck ?? contextConfig.SkipVersionCheck ?? false; bool ignoreNullValues = operationConfig.IgnoreNullValues ?? contextConfig.IgnoreNullValues ?? false; string overrideTableName = !string.IsNullOrEmpty(operationConfig.OverrideTableName) ? operationConfig.OverrideTableName : string.Empty; string tableNamePrefix = !string.IsNullOrEmpty(operationConfig.TableNamePrefix) ? operationConfig.TableNamePrefix : !string.IsNullOrEmpty(contextConfig.TableNamePrefix) ? contextConfig.TableNamePrefix : string.Empty; bool backwardQuery = operationConfig.BackwardQuery ?? false; string indexName = !string.IsNullOrEmpty(operationConfig.IndexName) ? operationConfig.IndexName : DefaultIndexName; List<ScanCondition> queryFilter = operationConfig.QueryFilter ?? new List<ScanCondition>(); ConditionalOperatorValues conditionalOperator = operationConfig.ConditionalOperator; DynamoDBEntryConversion conversion = operationConfig.Conversion ?? contextConfig.Conversion ?? DynamoDBEntryConversion.CurrentConversion; ConsistentRead = consistentRead; SkipVersionCheck = skipVersionCheck; IgnoreNullValues = ignoreNullValues; OverrideTableName = overrideTableName; TableNamePrefix = tableNamePrefix; BackwardQuery = backwardQuery; IndexName = indexName; QueryFilter = queryFilter; ConditionalOperator = conditionalOperator; Conversion = conversion; State = new OperationState(); }
/// <summary> /// Deletes an item in DynamoDB corresponding to a given hash primary key. /// /// No version check is done prior to delete. /// Type must be marked up with DynamoDBTableAttribute and at least /// one public field/property with DynamoDBHashKeyAttribute. /// </summary> /// <typeparam name="T">Type of object.</typeparam> /// <param name="hashKey">Hash key element of the object to delete.</param> /// <param name="operationConfig">Config object which can be used to override that table used.</param> internal void Delete <T>(object hashKey, DynamoDBOperationConfig operationConfig) { DynamoDBAsyncExecutor.IsMainThread("DeleteAsync"); Delete <T>(hashKey, null, operationConfig); }