Create odbc views with the deployer
Roxy now lets you create ODBC app servers. The next step is to create views.
Until I get around to implementing this feature, here's how you can do it using deploy/app_specific.rb (thanks to Bob Starbird). With the following defined, you can create the specified views locally using
$ ml local create_view
The specific view in this example is hard-coded, but if you need this feature, the example should tide you over until it's implemented.
class ServerConfig
def delete_view()
r = execute_query %Q{
xquery version "1.0-ml";
import module namespace view = "http://marklogic.com/xdmp/view"
at "/MarkLogic/views.xqy";
try {
view:remove(
"main",
"Compliance"
)
} catch ($e) { () }
(: Deletes a view, of the 'main' schema that contains columns, with a scope on the element, 'html'. :)
},
{ :db_name => @properties["ml.content-db"] }
end
def create_view()
r = execute_query %Q{
xquery version "1.0-ml";
import module namespace view = "http://marklogic.com/xdmp/view"
at "/MarkLogic/views.xqy";
try {
view:schema-create(
"main",
()
)
} catch ($e) {()},
view:create(
"main",
"Compliance",
view:element-view-scope(fn:QName("http://www.w3.org/1999/xhtml","html")),
( view:column("uri", cts:uri-reference()),
view:column("entityName", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityName"]/@content',("collation=http://marklogic.com/collation/"))),
view:column("entityStreetAddress", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityStreetAddress"]/@content',("collation=http://marklogic.com/collation/", ("nullable")))),
view:column("entityCityAddress", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityCityAddress"]/@content',("collation=http://marklogic.com/collation/", ("nullable")))),
view:column("entityCountryAddress", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "entityCountryAddress"]/@content',("collation=http://marklogic.com/collation//S2", ("nullable")))),
view:column("foreignEntityStatus", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "foreignEntityStatus"]/@content',("collation=http://marklogic.com/collation/", ("nullable")))),
view:column("intermediaryEntityStatus", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "intermediaryEntityStatus"]/@content',("collation=http://marklogic.com/collation/codepoint", ("nullable")))),
view:column("EIN", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "EIN"]/@content',("collation=http://marklogic.com/collation/", ("nullable")))),
view:column("docType", cts:path-reference('/xhtml:html/xhtml:head/xhtml:meta[@name eq "docType"]/@content',("collation=http://marklogic.com/collation//S1", ("nullable"))))
),
()
)
(: Creates a view, of the 'main' schema that contains columns, with a scope on the element, 'html'. :)
},
{ :db_name => @properties["ml.content-db"] }
end
end
I have used this mechanism to create triggers on a DB:-
def create_triggers() r = execute_query %Q{ xquery version "1.0-ml"; import module namespace trgr="http://marklogic.com/xdmp/triggers" at "/MarkLogic/triggers.xqy"; ( trgr:create-trigger("isys","ISys trigger", trgr:trigger-data-event( trgr:directory-scope("/imports/originals/","infinity"), trgr:document-content("create"), trgr:post-commit()), trgr:trigger-module(xdmp:database("SearchAndDiscovery-modules"),"/app/models","trigger-isys.xqy"), fn:true(), xdmp:default-permissions() )
,
trgr:create-trigger("isysupdate","ISys trigger", trgr:trigger-data-event( trgr:directory-scope("/imports/originals/","infinity"), trgr:document-content("modify"), trgr:post-commit()), trgr:trigger-module(xdmp:database("SearchAndDiscovery-modules"),"/app/models","trigger-isys.xqy"), fn:true(), xdmp:default-permissions() )
) }, { :db_name => @properties["ml.triggers-db"] } end