Skip to content

Instantly share code, notes, and snippets.

@jokokko
Created March 2, 2020 10:33
Show Gist options
  • Save jokokko/e74cb7dc86d01c1eb7c677550b924e7b to your computer and use it in GitHub Desktop.
Save jokokko/e74cb7dc86d01c1eb7c677550b924e7b to your computer and use it in GitHub Desktop.
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