Using databases with jolie

download Using databases with jolie

If you can't read please download the document

Transcript of Using databases with jolie

1. Using databases in Joliehttp://www.jolie-lang.orgCopyright 2014 The Jolie Team.This work is licensed under the Creative Commons Attribution License (CC BY).To view a copy of this license, visit https://creativecommons.org/licenses/by/4.0 2. Let's suppose you have a DatabaseThe name of your Database is MyDB and itcontains one table called Peopleid name surname1 John Smith2 Donald DuckYou want to develop a Jolie service able to readand to write from/into MyDB 3. Prepare librariesJolie connects databases through JDBC drivers.Prepare the JDBC .jar library of your databaseserver as it follows:libyourJDBCdriver.jaryour_service.ol1) Create a folder named lib in the same path whereyour jolie service is2) Put the JDBC .jar driver into the folder lib 4. Adding database.iolFirst of all, add Database.iol into your serviceinclude database.iol 5. Create the connectionConfigure connection anduse connect operationwith( connectionInfo ) {.host = 127.0.0.1;.driver = drivername; //ex: postgresql.port = 5432;.database = MyDB;.username = myusername;.password = mypassword};connect@Database( connectionInfo )() 6. Create a queryJolie is equipped with protection against SQLinjection. You can pass parameters to the query.q = select name from people where id>:id;q.id = 0;Parameters in SQL queriesare prefixed with :Parameters values arepassed as message fieldsquery@Database( q )( result ); 7. Get the resultRows are listed in subvector row wheresubfields are column.result.row[0].name = John.surname = Smith.row[1].name = Donald.surname = Duck 8. Update the tableUpdate a table it is easy, use updateoperation instead of query.q = insert into people (name,surname)values (:name,:surname);q.name = Homer;q.surname = Simpsons;update@Database( q )( result ) 9. The first language formicroserviceshttp://www.jolie-lang.orgCopyright 2014 The Jolie Team.This work is licensed under the Creative Commons Attribution License (CC BY).To view a copy of this license, visit https://creativecommons.org/licenses/by/4.0 10. The first language formicroserviceshttp://www.jolie-lang.orgCopyright 2014 The Jolie Team.This work is licensed under the Creative Commons Attribution License (CC BY).To view a copy of this license, visit https://creativecommons.org/licenses/by/4.0