public void CanCreateSqlEtlTransformScriptWithGuidWhenTableTypeGuid(MigrationProvider provider) { using (var store = GetDocumentStore()) { using (WithSqlDatabase(provider, out var connectionString, out string schemaName, dataSet: null, includeData: false)) { GetCreateTableWithUniqueType(provider, connectionString); CheckCount(provider, connectionString, 0); var sqlEtlConfigurationName = "test_" + Guid.NewGuid(); var connectionStringName = $"test_{store.Database}"; var operation = new PutConnectionStringOperation <SqlConnectionString>(new SqlConnectionString { Name = connectionStringName, FactoryName = GetFactoryName(provider), ConnectionString = connectionString }); store.Maintenance.Send(operation); var etlDone = new ManualResetEventSlim(); var configuration = new SqlEtlConfiguration { Name = sqlEtlConfigurationName, ConnectionStringName = connectionStringName, SqlTables = { new SqlEtlTable { TableName = "TestGuidEtls", DocumentIdColumn = "Id" }, },
public void Initialize(DocumentStore store) { var connectionString = new SqlConnectionString { Name = ConnectionStringName, ConnectionString = SqlEtlTests.MasterDatabaseConnection.Value + $";Initial Catalog={SqlDatabaseName}" }; var putConnectionStringOperation = new PutConnectionStringOperation <SqlConnectionString>(connectionString, store.Database); store.Maintenance.Server.Send(putConnectionStringOperation); DatabaseRecord record; using (Server.ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context)) using (context.OpenReadTransaction()) { record = Server.ServerStore.Cluster.ReadDatabase(context, store.Database); } _connectionString = record.SqlConnectionStrings[ConnectionStringName].ConnectionString; using (var con = new SqlConnection(SqlEtlTests.MasterDatabaseConnection.Value)) { con.Open(); using (var dbCommand = con.CreateCommand()) { dbCommand.CommandText = string.Format(CreateDatabaseQuery, SqlDatabaseName); dbCommand.ExecuteNonQuery(); } } var assembly = Assembly.GetExecutingAssembly(); using (var con = new SqlConnection(_connectionString)) { con.Open(); using (var dbCommand = con.CreateCommand()) { var textStreamReader = new StreamReader(assembly.GetManifestResourceStream("SlowTests.Data.create.sql")); dbCommand.CommandText = textStreamReader.ReadToEnd(); dbCommand.ExecuteNonQuery(); } using (var dbCommand = con.CreateCommand()) { var textStreamReader = new StreamReader(assembly.GetManifestResourceStream("SlowTests.Data.insert.sql")); dbCommand.CommandText = textStreamReader.ReadToEnd(); dbCommand.ExecuteNonQuery(); } } }
public AddEtl() { using (var store = new DocumentStore()) { #region add_raven_etl AddEtlOperation <RavenConnectionString> operation = new AddEtlOperation <RavenConnectionString>( new RavenEtlConfiguration { ConnectionStringName = "raven-connection-string-name", Name = "Employees ETL", Transforms = { new Transformation { Name = "Script #1", Collections = { "Employees" }, Script = @"loadToEmployees ({ Name: this.FirstName + ' ' + this.LastName, Title: this.Title });" } } }); AddEtlOperationResult result = store.Maintenance.Send(operation); #endregion } using (var store = new DocumentStore()) #region raven_etl_connection_string { //define connection string var ravenConnectionString = new RavenConnectionString() { //name connection string Name = "raven-connection-string-name", //define appropriate node //Be sure that the node definition in the connection string has the "s" in https TopologyDiscoveryUrls = new[] { "https://127.0.0.1:8080" }, //define database to connect with on the node Database = "Northwind", }; //create the connection string var resultRavenString = store.Maintenance.Send( new PutConnectionStringOperation <RavenConnectionString>(ravenConnectionString)); } #endregion { using (var store = new DocumentStore()) { #region add_sql_etl AddEtlOperation <SqlConnectionString> operation = new AddEtlOperation <SqlConnectionString>( new SqlEtlConfiguration { ConnectionStringName = "sql-connection-string-name", FactoryName = "System.Data.SqlClient", Name = "Orders to SQL", SqlTables = { new SqlEtlTable { TableName = "Orders", DocumentIdColumn = "Id", InsertOnlyMode = false }, new SqlEtlTable { TableName = "OrderLines", DocumentIdColumn = "OrderId", InsertOnlyMode = false }, }, Transforms = { new Transformation { Name = "Script #1", Collections = { "Orders" }, Script = @"var orderData = { Id: id(this), OrderLinesCount: this.Lines.length, TotalCost: 0 }; for (var i = 0; i < this.Lines.length; i++) { var line = this.Lines[i]; orderData.TotalCost += line.PricePerUnit; // Load to SQL table 'OrderLines' loadToOrderLines({ OrderId: id(this), Qty: line.Quantity, Product: line.Product, Cost: line.PricePerUnit }); } orderData.TotalCost = Math.round(orderData.TotalCost * 100) / 100; // Load to SQL table 'Orders' loadToOrders(orderData)" } } }); AddEtlOperationResult result = store.Maintenance.Send(operation); #endregion } using (var store = new DocumentStore()) #region sql_etl_connection_string { // define new connection string PutConnectionStringOperation <SqlConnectionString> operation = new PutConnectionStringOperation <SqlConnectionString>( new SqlConnectionString { // name connection string Name = "local_mysql", // define FactoryName FactoryName = "MySql.Data.MySqlClient", // define database - may also need to define authentication and encryption parameters // by default, encrypted databases are sent over encrypted channels ConnectionString = "host=127.0.0.1;user=root;database=Northwind" }); // create connection string PutConnectionStringResult connectionStringResult = store.Maintenance.Send(operation); } #endregion } }
public ConnectionStrings() { using (var store = new DocumentStore()) { #region add_raven_connection_string PutConnectionStringOperation <RavenConnectionString> operation = new PutConnectionStringOperation <RavenConnectionString>( new RavenConnectionString { Name = "raven2", Database = "Northwind2", TopologyDiscoveryUrls = new[] { "http://rvn2:8080" } }); PutConnectionStringResult connectionStringResult = store.Maintenance.Send(operation); #endregion } using (var store = new DocumentStore()) { #region add_sql_connection_string PutConnectionStringOperation <SqlConnectionString> operation = new PutConnectionStringOperation <SqlConnectionString>( new SqlConnectionString { Name = "local_mysql", FactoryName = "MySql.Data.MySqlClient", ConnectionString = "host=127.0.0.1;user=root;database=Northwind" }); PutConnectionStringResult connectionStringResult = store.Maintenance.Send(operation); #endregion } using (var store = new DocumentStore()) { #region get_all_connection_strings GetConnectionStringsOperation operation = new GetConnectionStringsOperation(); GetConnectionStringsResult connectionStrings = store.Maintenance.Send(operation); Dictionary <string, SqlConnectionString> sqlConnectionStrings = connectionStrings.SqlConnectionStrings; Dictionary <string, RavenConnectionString> ravenConnectionStrings = connectionStrings.RavenConnectionStrings; #endregion } using (var store = new DocumentStore()) { #region get_connection_string_by_name GetConnectionStringsOperation operation = new GetConnectionStringsOperation("local_mysql", ConnectionStringType.Sql); GetConnectionStringsResult connectionStrings = store.Maintenance.Send(operation); Dictionary <string, SqlConnectionString> sqlConnectionStrings = connectionStrings.SqlConnectionStrings; SqlConnectionString mysqlConnectionString = sqlConnectionStrings["local_mysql"]; #endregion } using (var store = new DocumentStore()) { RavenConnectionString connectionString = null; #region remove_raven_connection_string RemoveConnectionStringOperation <RavenConnectionString> operation = new RemoveConnectionStringOperation <RavenConnectionString>( connectionString); store.Maintenance.Send(operation); #endregion } using (var store = new DocumentStore()) { SqlConnectionString connectionString = null; #region remove_sql_connection_string RemoveConnectionStringOperation <SqlConnectionString> operation = new RemoveConnectionStringOperation <SqlConnectionString>( connectionString); store.Maintenance.Send(operation); #endregion } }
public ConnectionStrings() { using (var store = new DocumentStore()) { #region add_raven_connection_string PutConnectionStringOperation <RavenConnectionString> operation = new PutConnectionStringOperation <RavenConnectionString>( new RavenConnectionString { Name = "raven2", Database = "Northwind2", TopologyDiscoveryUrls = new[] { // Be sure to include the "s" in https for secure servers. "https://rvn2:8080" } }); PutConnectionStringResult connectionStringResult = store.Maintenance.Send(operation); #endregion } using (var store = new DocumentStore()) { #region add_sql_connection_string PutConnectionStringOperation <SqlConnectionString> operation = new PutConnectionStringOperation <SqlConnectionString>( new SqlConnectionString { Name = "local_mysql", FactoryName = "MySql.Data.MySqlClient", ConnectionString = "host=127.0.0.1;user=root;database=Northwind" }); PutConnectionStringResult connectionStringResult = store.Maintenance.Send(operation); #endregion } #region get_all_connection_strings using (var store = new DocumentStore()) { GetConnectionStringsOperation operation = new GetConnectionStringsOperation(); GetConnectionStringsResult connectionStrings = store.Maintenance.Send(operation); Dictionary <string, SqlConnectionString> sqlConnectionStrings = connectionStrings.SqlConnectionStrings; Dictionary <string, RavenConnectionString> ravenConnectionStrings = connectionStrings.RavenConnectionStrings; } #endregion #region get_connection_string_by_name using (var store = new DocumentStore()) { GetConnectionStringsOperation operation = new GetConnectionStringsOperation("local_mysql", ConnectionStringType.Sql); GetConnectionStringsResult connectionStrings = store.Maintenance.Send(operation); Dictionary <string, SqlConnectionString> sqlConnectionStrings = connectionStrings.SqlConnectionStrings; SqlConnectionString mysqlConnectionString = sqlConnectionStrings["local_mysql"]; } #endregion using (var store = new DocumentStore()) { RavenConnectionString connectionString = null; #region remove_raven_connection_string RemoveConnectionStringOperation <RavenConnectionString> operation = new RemoveConnectionStringOperation <RavenConnectionString>( connectionString); store.Maintenance.Send(operation); #endregion } using (var store = new DocumentStore()) { SqlConnectionString connectionString = null; #region remove_sql_connection_string RemoveConnectionStringOperation <SqlConnectionString> operation = new RemoveConnectionStringOperation <SqlConnectionString>( connectionString); store.Maintenance.Send(operation); #endregion } using (var store = new DocumentStore()) #region raven_etl_connection_string { //define connection string var ravenConnectionString = new RavenConnectionString() { //name connection string Name = "raven-connection-string-name", //define appropriate node //Be sure that the node definition in the connection string has the "s" in https TopologyDiscoveryUrls = new[] { "https://127.0.0.1:8080" }, //define database to connect with on the node Database = "Northwind", }; //create the connection string var resultRavenString = store.Maintenance.Send( new PutConnectionStringOperation <RavenConnectionString>(ravenConnectionString)); } #endregion using (var store = new DocumentStore()) #region sql_etl_connection_string { // define new connection string PutConnectionStringOperation <SqlConnectionString> operation = new PutConnectionStringOperation <SqlConnectionString>( new SqlConnectionString { // name connection string Name = "local_mysql", // define FactoryName FactoryName = "MySql.Data.MySqlClient", // define database - may also need to define authentication and encryption parameters // by default, encrypted databases are sent over encrypted channels ConnectionString = "host=127.0.0.1;user=root;database=Northwind" }); // create connection string PutConnectionStringResult connectionStringResult = store.Maintenance.Send(operation); } #endregion }