Created
February 20, 2015 15:15
-
-
Save di97mni/704352647ce6ed151f01 to your computer and use it in GitHub Desktop.
Split RavenDB indexes in different databases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//<?xml version="1.0" encoding="utf-8"?> | |
//<packages> | |
// <package id="NodaTime" version="1.3.0" targetFramework="net451" /> | |
// <package id="RavenDB.Bundles.NodaTime" version="3.0.0" targetFramework="net451" /> | |
// <package id="RavenDB.Client" version="3.0.3528" targetFramework="net451" /> | |
// <package id="RavenDB.Client.NodaTime" version="3.0.0" targetFramework="net451" /> | |
// <package id="RavenDB.Database" version="3.0.3528" targetFramework="net451" /> | |
// <package id="RavenDB.Tests.Helpers" version="3.0.3528" targetFramework="net451" /> | |
// <package id="xunit" version="1.9.2" targetFramework="net451" /> | |
//</packages> | |
using System.ComponentModel.Composition.Hosting; | |
using System.Linq; | |
using NodaTime; | |
using Raven.Abstractions.Indexing; | |
using Raven.Bundles.NodaTime; | |
using Raven.Client.Embedded; | |
using Raven.Client.Extensions; | |
using Raven.Client.Indexes; | |
using Raven.Client.NodaTime; | |
using Raven.Tests.Helpers; | |
using Xunit; | |
namespace Tests | |
{ | |
public class NodaTimeBundleTest : RavenTestBase | |
{ | |
[Fact] | |
public void Can_create_Nodatime_index_in_default_db() | |
{ | |
var store = new EmbeddableDocumentStore | |
{ | |
RunInMemory = true | |
}; | |
store.Configuration.Catalog.Catalogs.Add(new AssemblyCatalog(typeof (NodaTimeCompilationExtension).Assembly)); | |
store.Initialize(); | |
store.ConfigureForNodaTime(DateTimeZoneProviders.Bcl); | |
var catalog = new CompositionContainer(new TypeCatalog(typeof (SomeClassIndex))); | |
IndexCreation.CreateIndexes(catalog, store); | |
} | |
[Fact] | |
public void Can_create_Nodatime_index_in_another_db() | |
{ | |
var store = new EmbeddableDocumentStore | |
{ | |
RunInMemory = true | |
}; | |
store.Configuration.Catalog.Catalogs.Add(new AssemblyCatalog(typeof (NodaTimeCompilationExtension).Assembly)); | |
store.Initialize(); | |
store.ConfigureForNodaTime(DateTimeZoneProviders.Bcl); | |
var defaultDbCatalog = new CompositionContainer(new TypeCatalog(typeof (SomeClassIndex))); | |
IndexCreation.CreateIndexes(defaultDbCatalog, store); | |
const string dbName = "anotherDb"; | |
store.DatabaseCommands.GlobalAdmin.EnsureDatabaseExists(dbName); | |
var dbCatalog = new CompositionContainer(new TypeCatalog(typeof (AnotherClassIndex))); | |
IndexCreation.CreateIndexes(dbCatalog, store.DatabaseCommands.ForDatabase(dbName), store.Conventions); | |
} | |
} | |
public class SomeClassIndex : AbstractIndexCreationTask<SomeClass> | |
{ | |
public SomeClassIndex() | |
{ | |
Map = docs => from doc in docs | |
select new | |
{ | |
doc.LocalDate, | |
Span = doc.LocalDate.AsLocalDate().DaysBetween(doc.LocalDate.AsLocalDate()) | |
}; | |
StoreAllFields(FieldStorage.Yes); | |
} | |
} | |
public class AnotherClassIndex : AbstractIndexCreationTask<AnotherClass> | |
{ | |
public AnotherClassIndex() | |
{ | |
Map = docs => from doc in docs | |
select new | |
{ | |
doc.LocalDate, | |
Span = doc.LocalDate.AsLocalDate().DaysBetween(doc.LocalDate.AsLocalDate()) | |
}; | |
StoreAllFields(FieldStorage.Yes); | |
} | |
} | |
public class SomeClass | |
{ | |
public LocalDate LocalDate { get; set; } | |
} | |
public class AnotherClass | |
{ | |
public LocalDate LocalDate { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment