public Examples() { // This is where you configure nevermore. The config lets you control how JSON is serialized and a whole lot // more. We'll start simple. var config = new RelationalStoreConfiguration(ConnectionString); // Your mappings define how your documents will be stored in the database. You need to tell Nevermore about // all your mappings. config.DocumentMaps.Register(new PersonMap()); // Create your store. You'll do this once when the application starts up. store = new RelationalStore(config); // Of course, this is a SQL database, so you'll need a SQL schema. Here's ours. ExecuteSql(@" CREATE TABLE [Person] ( [Id] NVARCHAR(50) NOT NULL CONSTRAINT [PK__Id] PRIMARY KEY CLUSTERED, [FirstName] NVARCHAR(20) NOT NULL, [LastName] NVARCHAR(200) NULL, [Email] NVARCHAR(200) NOT NULL, [JSON] NVARCHAR(MAX) NOT NULL ) ALTER TABLE [Person] ADD CONSTRAINT [UQ_UniquePersonEmail] UNIQUE([Email]) "); }
protected FixtureWithRelationalStore() { var config = new RelationalStoreConfiguration(ConnectionString); config.CommandFactory = new ChaosSqlCommandFactory(new SqlCommandFactory()); config.ApplicationName = "Nevermore-IntegrationTests"; config.DefaultSchema = "TestSchema"; config.DocumentMaps.Register( new CustomerMap(), new BrandMap(), new ProductMap(), new LineItemMap(), new MachineMap(), new OrderMap()); config.TypeHandlers.Register(new ReferenceCollectionTypeHandler()); config.InstanceTypeResolvers.Register(new ProductTypeResolver()); config.InstanceTypeResolvers.Register(new BrandTypeResolver()); config.UseJsonNetSerialization(settings => { settings.ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor; }); GenerateSchemaAutomatically( new OrderMap(), new ProductMap(), new CustomerMap(), new LineItemMap(), new BrandMap(), new MachineMap()); Store = new RelationalStore(config); }
public override void SetUp() { base.SetUp(); var config = new RelationalStoreConfiguration(ConnectionString); config.DocumentMaps.Register(new BigObjectMap(Format)); store = new RelationalStore(config); readTransaction = store.BeginReadTransaction(); using var writer = store.BeginWriteTransaction(); var rand = new Random(42); var randomString = new Func <string>(() => { var buffer = new byte[3]; rand.NextBytes(buffer); return(Convert.ToBase64String(buffer)); }); var historyEntries = Enumerable.Range(1, DocumentSize / 256).Select(n => new BigObjectHistoryEntry { Id = Guid.NewGuid(), Comment = randomString(), LuckyNumbers = Enumerable.Range(0, rand.Next(130, 330)).ToArray(), Date = DateTime.Today.AddDays(n) }); writer.Insert(new BigObject { Id = "BigObject-1", History = historyEntries.OfType <object>().ToList() }); writer.Commit(); }
public override void SetUp() { base.SetUp(); var config = new RelationalStoreConfiguration(ConnectionString); config.DocumentMaps.Register(new CustomerMap()); store = new RelationalStore(config); transaction = store.BeginReadTransaction(); }
public override void SetUp() { base.SetUp(); var config = new RelationalStoreConfiguration(ConnectionString); config.DocumentMaps.Register(new CustomerMap()); store = new RelationalStore(config); transaction = store.BeginReadTransaction(); allIdsRandomlySorted = transaction.Query <Customer>().ToList().Select(p => p.Id).OrderByDescending(p => Guid.NewGuid()).ToList(); }
public void ShouldSetDefaultConnectionStringOptions() { var config = new RelationalStoreConfiguration("Server=(local);") { ApplicationName = "Nevermore test" }; var connectionStringBuilder = new SqlConnectionStringBuilder(config.ConnectionString); connectionStringBuilder.ConnectTimeout.Should().Be(NevermoreDefaults.DefaultConnectTimeoutSeconds); connectionStringBuilder.ConnectRetryCount.Should().Be(NevermoreDefaults.DefaultConnectRetryCount); connectionStringBuilder.ConnectRetryInterval.Should().Be(NevermoreDefaults.DefaultConnectRetryInterval); }
IDeleteQueryBuilder <TDocument> CreateQueryBuilder <TDocument>() where TDocument : class { var configuration = new RelationalStoreConfiguration("a") { DocumentMaps = mappings }; configuration.DocumentSerializer = new NewtonsoftDocumentSerializer(configuration); return(new DeleteQueryBuilder <TDocument>( new UniqueParameterNameGenerator(), new DataModificationQueryBuilder(configuration, s => null), queryExecutor )); }
public void ShouldNotOverrideExplicitConnectionStringOptions() { var config = new RelationalStoreConfiguration("Server=(local);Connection Timeout=123;ConnectRetryCount=123;ConnectRetryInterval=59;") { ApplicationName = "Nevermore test" }; var connectionStringBuilder = new SqlConnectionStringBuilder(config.ConnectionString); connectionStringBuilder.ConnectTimeout.Should().Be(123); connectionStringBuilder.ConnectRetryCount.Should().Be(123); connectionStringBuilder.ConnectRetryInterval.Should().Be(59); }
public DataModificationQueryBuilderFixture() { var configuration = new RelationalStoreConfiguration(""); configuration.DocumentSerializer = new NewtonsoftDocumentSerializer(configuration); configuration.DocumentMaps.Register( new TestDocumentMap(), new TestDocumentWithRelatedDocumentsMap(), new TestDocumentWithMultipleRelatedDocumentsMap(), new OtherMap()); builder = new DataModificationQueryBuilder( configuration, m => idAllocator() ); }
public DocumentReaderStrategy(RelationalStoreConfiguration configuration) { this.configuration = configuration; }
public ArbitraryClassReaderStrategy(RelationalStoreConfiguration configuration) { this.configuration = configuration; }
public override void SetUp() { base.SetUp(); var config = new RelationalStoreConfiguration(ConnectionString); config.DocumentMaps.Register(new BigObjectMap(JsonStorageFormat.TextOnly)); store = new RelationalStore(config); readTransaction = store.BeginReadTransaction(); using var writer = store.BeginWriteTransaction(); var history = GenerateHistory(); var doc1 = history.Take(1).ToList(); var doc10 = history.Take(10).ToList(); var doc100 = history.Take(100).ToList(); var doc500 = history.Take(500).ToList(); var rand = new Random(42); for (var i = 0; i < 1000; i++) { var doc = new BigObject { Name = "Document " + i }; var distribution = rand.Next(1, 100); if (distribution < 70) { doc.History = doc1; } else if (distribution < 85) { doc.History = doc10; } else if (distribution < 95) { doc.History = doc100; } else if (distribution <= 100) { doc.History = doc500; } writer.Insert(doc, new InsertOptions { CommandTimeout = TimeSpan.FromSeconds(180) }); if (i % 100 == 0) { Console.WriteLine($"Inserted: {i} history: {doc.History.Count} rand: {distribution}"); } } foreach (var item in writer.Stream <(long?Bucket, int?Count)>( "select len([JSON]) as Bucket, count(*) from BigObject group by len([JSON]) order by len([JSON])")) { Console.WriteLine($"{item.Bucket} bytes: {item.Count} documents"); } writer.Commit(); }
public PrimitiveReaderStrategy(RelationalStoreConfiguration configuration) { this.configuration = configuration; }
public ValueTupleReaderStrategy(RelationalStoreConfiguration configuration) { this.configuration = configuration; }