public Task <AppliedInfo <T> > InsertIfNotExistsAsync <T>(T poco, CqlQueryOptions queryOptions = null) { // Get statement and bind values from POCO var cql = _cqlGenerator.GenerateInsert <T>(true); var getBindValues = _mapperFactory.GetValueCollector <T>(cql); var values = getBindValues(poco); return(ExecuteAsyncAndAdapt( Cql.New(cql, values, queryOptions ?? CqlQueryOptions.None), (stmt, rs) => AppliedInfo <T> .FromRowSet(_mapperFactory, cql, rs))); }
/// <inheritdoc /> public async Task <AppliedInfo <T> > ExecuteConditionalAsync <T>(ICqlBatch batch) { if (batch == null) { throw new ArgumentNullException("batch"); } var batchStatement = await _statementFactory .GetBatchStatementAsync(_session, batch) .ConfigureAwait(false); //Use the concatenation of cql strings as hash for the mapper var cqlString = string.Join(";", batch.Statements.Select(s => s.Statement)); var rs = await _session.ExecuteAsync(batchStatement).ConfigureAwait(false); return(AppliedInfo <T> .FromRowSet(_mapperFactory, cqlString, rs)); }
/// <inheritdoc /> public Task <AppliedInfo <T> > InsertIfNotExistsAsync <T>(T poco, bool insertNulls, int?ttl, CqlQueryOptions queryOptions = null) { var pocoData = _mapperFactory.PocoDataFactory.GetPocoData <T>(); var queryIdentifier = string.Format("INSERT ID {0}/{1}", pocoData.KeyspaceName, pocoData.TableName); var getBindValues = _mapperFactory.GetValueCollector <T>(queryIdentifier); //get values first to identify null values var values = getBindValues(poco); object[] queryParameters; //generate INSERT query based on null values (if insertNulls set) var cql = _cqlGenerator.GenerateInsert <T>(insertNulls, values, out queryParameters, true, ttl); return(ExecuteAsyncAndAdapt( Cql.New(cql, queryParameters, queryOptions ?? CqlQueryOptions.None), (stmt, rs) => AppliedInfo <T> .FromRowSet(_mapperFactory, cql, rs))); }
public Task <AppliedInfo <T> > ExecuteConditionalAsync <T>(ICqlBatch batch) { if (batch == null) { throw new ArgumentNullException("batch"); } return(_statementFactory .GetBatchStatementAsync(_session, batch.Statements, batch.BatchType) .Continue(t1 => { //Use the concatenation of cql strings as hash for the mapper var cqlString = String.Join(";", batch.Statements.Select(s => s.Statement)); var batchStatement = t1.Result; return _session.ExecuteAsync(batchStatement) .Continue(t2 => AppliedInfo <T> .FromRowSet(_mapperFactory, cqlString, t2.Result)); }) .Unwrap()); }
/// <inheritdoc /> public Task <AppliedInfo <T> > InsertIfNotExistsAsync <T>(T poco, string executionProfile, bool insertNulls, int?ttl, CqlQueryOptions queryOptions = null) { if (executionProfile == null) { throw new ArgumentNullException(nameof(executionProfile)); } var pocoData = _mapperFactory.PocoDataFactory.GetPocoData <T>(); var queryIdentifier = $"INSERT ID {pocoData.KeyspaceName}/{pocoData.TableName}"; var getBindValues = _mapperFactory.GetValueCollector <T>(queryIdentifier); //get values first to identify null values var values = getBindValues(poco); //generate INSERT query based on null values (if insertNulls set) var cql = _cqlGenerator.GenerateInsert <T>(insertNulls, values, out var queryParameters, true, ttl); var cqlInstance = Cql.New(cql, queryParameters, queryOptions ?? CqlQueryOptions.None).WithExecutionProfile(executionProfile); return(ExecuteAsyncAndAdapt( cqlInstance, (stmt, rs) => AppliedInfo <T> .FromRowSet(_mapperFactory, cql, rs))); }
/// <inheritdoc /> public Task <AppliedInfo <T> > DeleteIfAsync <T>(Cql cql) { _cqlGenerator.PrependDelete <T>(cql); return(ExecuteAsyncAndAdapt(cql, (stmt, rs) => AppliedInfo <T> .FromRowSet(_mapperFactory, cql.Statement, rs))); }