English 中文(简体)
Can different OPA apps share Databases?
原标题:
  • 时间:2011-07-27 10:01:35
  •  标签:
  • opa

I m just investigating OPA and trying to make the leap from a traditional LAMP background, so here s my first of many newbie questions:

Can I have two OPA apps sharing the same database, say one which writes into a database and another that reads from it?

最佳回答

Yes, it s certainly possible. A simple but complete example:

[db.opa]

database ./counter
db /counter : int
Counter = {{
  read() = /counter
  inc() = /counter <- read() + 1
}}

[db_read.opa]

server = one_page_server("Counter app", -> <>Counter value: {Counter.read()}</>)

[db_write.opa]

_ = Scheduler.timer(1000, -> Counter.inc())

Compile with:

 opa db_read.opa db.opa -o db_read.exe
 opa db_write.opa db.opa -o db_write.exe

Run the database server for database counter on port 5001:

 opa-db-server -b 127.0.0.1:5001 --db-local counter

Run the applications, connecting to this database:

 ./db_read.exe --db-remote 127.0.0.1:5001
 ./db_write.exe --db-remote 127.0.0.1:5001

The db_write app updates the counter every second. You can see that with the db_read app by visiting localhost:8080 (and refreshing the page).

Hope the Opa-DB experts will correct me if I got something wrong.

问题回答

暂无回答




相关问题
Can different OPA apps share Databases?

I m just investigating OPA and trying to make the leap from a traditional LAMP background, so here s my first of many newbie questions: Can I have two OPA apps sharing the same database, say one ...

Equivalent of List.exists for Db

I ve used List.exists( ), i woudl like to know if there is an equivalent for Db. If i have a function f(e) : bool, i would like to know if there is at least one element e, with f(e) -> true. ...

Looping over db intmap(person)

example: type person = { name : string ; age : int } db /person : intmap(person) I know how to get a single person from the db, but how do I get them all? and print ...

Can opa extensions be written in Ocaml?

I notice that included in the source of the OpaWhiteBoard example, there is a .ml file here: https://github.com/hhugo/OpaWhiteBoard/blob/master/src/opacairo/cairo.ml This appears to be OCaml with ...

Access a record field

This code source don t compile, Is there a way to make that in OPA ? type User = { nom : string ; prenom : string } un_user = { nom = "My_name" ; prenom = "My_last_name" } : User champ = "nom" do ...

OPA syntax question

I have seen in the stdlib and in some github project. Code like that : MyClass = field_id(id) = "{id}_field" {{ my_func(args) = output }} What the interest to have function before the {{ }} ...

热门标签