Created
March 2, 2020 10:33
-
-
Save jokokko/e74cb7dc86d01c1eb7c677550b924e7b to your computer and use it in GitHub Desktop.
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
class MyFeature : FeatureSchemaBase | |
{ | |
class MyFunc : Function | |
{ | |
public MyFunc(string schema) : base(new DbObjectName(schema, "hello")) | |
{ | |
} | |
public override void Write(DdlRules rules, StringWriter writer) | |
{ | |
writer.WriteLine( | |
$@"CREATE OR REPLACE FUNCTION {Identifier}() RETURNS text AS $$ | |
BEGIN | |
RETURN 'world'; | |
END; | |
$$ LANGUAGE plpgsql;"); | |
} | |
protected override string toDropSql() | |
{ | |
return $"drop function {Identifier}"; | |
} | |
} | |
public MyFeature(StoreOptions options) : base(nameof(MyFeature), options) | |
{ | |
} | |
protected override IEnumerable<ISchemaObject> schemaObjects() | |
{ | |
yield return new MyFunc(Options.DatabaseSchemaName); | |
} | |
} | |
.. | |
var store = DocumentStore.For(c => | |
{ | |
c.Storage.Add<MyFeature>(); | |
}); | |
store.Schema.ApplyAllConfiguredChangesToDatabase(); | |
using (var s = store.OpenSession()) | |
{ | |
var str = s.Query<string>("select hello()").First(); | |
Console.WriteLine(str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment