TreSQL (Tree SQL)     Mārtiņš Rumovskis
Agenda   Motivation   TreSQL vs SQL   TreSQL statement structure   Scala API
Agenda   Motivation   TreSQL vs SQL   TreSQL statement structure   Scala API
Old Good SQL   Traditionally we can get data in the tabular form        DEPTNO     DNAME      LOC        30         SALES...
Old Good SQL   Traditionally we can get data in the tabular form        DEPTNO     DNAME       LOC        30         SALE...
Old Good SQL   Traditionally we can get data in the tabular form         DEPTNO          DNAME        LOC         30     ...
Old Good SQL (Cont)   We need to write joins       select * from emp e join dept d on e.deptno = d.deptno
Old Good SQL (Cont)   We need to write joins       select * from emp e join dept d on e.deptno = d.deptno   Explicitly s...
Problems of JDBC   JDBC       We need to do SQL to Java mappings        setXXX(idx, value)                         ...we...
Problems of JDBC   JDBC       We need to do SQL to Java mappings        setXXX(idx, value)                         ...we...
What’s about ORM?   ORM (Hibernate)       We need to define class model and mapping
What’s about ORM?   ORM (Hibernate)       We need to define class model and mapping       And we still need SQL (for ad...
Agenda   Motivation   TreSQL vs SQL   TreSQL statement structure   Scala API
Sql vs TreSQL   Simple SQL    SQL: select * from dept
Sql vs TreSQL   Simple SQL    SQL: select * from dept    TreSQL:      dept
Sql vs TreSQL   Select... Where    SQL: select * from dept where deptno = 10
Sql vs TreSQL   Select... Where    SQL: select * from dept where deptno = 10    TreSQL:       dept[10]
Sql vs TreSQL   More complex select    SQL: select deptno, dname from dept           select ename from emp where deptno =...
Sql vs TreSQL   More complex select (needs programming when using    SQL)    SQL: select deptno, dname from dept         ...
Sql vs TreSQL   Multiple selects    SQL: select * from dept where deptno = 10         select * from emp where job = MGR
Sql vs TreSQL   Multiple selects    SQL: select * from dept where deptno = 10         select * from emp where job = MGR‘ ...
Sql vs TreSQL   Outer join order by    SQL: select * from dept            left join emp on dept.deptno = emp.deptno      ...
Sql vs TreSQL   Outer join order by    SQL: select * from dept              left join emp on dept.deptno = emp.deptno    ...
Sql vs TreSQL   In, subselect    SQL: select * from dept where deptno              in (select deptno from emp)
Sql vs TreSQL   In, subselect    SQL: select * from dept where deptno              in (select deptno from emp)    TreSQL:...
Sql vs TreSQL   Exists, correlated subselect    SQL: select * from dept d where             exists select * from emp e   ...
Sql vs TreSQL   Exists, correlated subselect    SQL: select * from dept d where             exists select * from emp e   ...
Sql vs TreSQL   More complex example (using SQL programming is    needed)    dept{deptno, dname,         |emp[sal >= hisa...
Agenda   Motivation   TreSQL vs SQL   TreSQL statement structure   Scala API
TreSQL Language Structure   SELECT statement structure    <from>[<where>][<columns>][<group by>    [<having>]][<order>][<...
TreSQL Language Structure   INSERT    DEPT {DEPTNO, DNAME, LOC}        + [10, "ACCOUNTING", "NEW YORK"]   Statement stru...
TreSQL Language Structure   UPDATE    emp[1] {ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO} =    [?, ?, ?, ?, ?, ?, ?]  ...
TreSQL Language Structure   DELETE    emp - [1]   Statement structure    table - [where]
Agenda   Motivation   TreSQL vs SQL   TreSQL statement structure   Scala API
Scala API    Code example:import org.tresql._Env update connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(...
Scala API    Code example:import org.tresql._       org.tresql.Env                          Expression execution environm...
Scala API    Code example:import org.tresql._Env update connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(...
Scala API    Code example:import org.tresql._Env update connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(...
Scala API    Code example:import org.tresql._Env update connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(...
Scala API    Code example:import org.tresql._org.tresql.Env update connectionorg.tresql.Query.foreach("dept[?]{dname}", 1...
Scala API   Code example:import org.tresql._org.tresql.Env update connectionorg.tresql.Query.foreach("emp[sal > ? & deptn...
That’s about it!                   Visit: https://github.com/mrumkovskis/Query
Q&A
Upcoming SlideShare
Loading in …5
×

TreSQL

1,350 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,350
On SlideShare
0
From Embeds
0
Number of Embeds
127
Actions
Shares
0
Downloads
10
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

TreSQL

  1. 1. TreSQL (Tree SQL) Mārtiņš Rumovskis
  2. 2. Agenda Motivation TreSQL vs SQL TreSQL statement structure Scala API
  3. 3. Agenda Motivation TreSQL vs SQL TreSQL statement structure Scala API
  4. 4. Old Good SQL Traditionally we can get data in the tabular form DEPTNO DNAME LOC 30 SALES Chicago
  5. 5. Old Good SQL Traditionally we can get data in the tabular form DEPTNO DNAME LOC 30 SALES Chicago But we need something like this... DEPTNO DNAME LOC EMPNO ENAME 30 SALES Chicago 1 ALLEN 2 WARD 3 MARTIN 20 RESEARCH Dallas 4 MILLER 5 SCOTT
  6. 6. Old Good SQL Traditionally we can get data in the tabular form DEPTNO DNAME LOC 30 SALES Chicago But we need somethink like this... DEPTNO DNAME LOC EMPNO ENAME 30 SALES Chicago 1 ALLEN 2 WARD 3 MARTIN 20 RESEARCH Dallas 4 MILLER 5 SCOTT Or like this... NAME DRIVER_LIC LANGUAGES SCOTT A,B EN,LV,RU MILLER B,C EN,IT
  7. 7. Old Good SQL (Cont) We need to write joins select * from emp e join dept d on e.deptno = d.deptno
  8. 8. Old Good SQL (Cont) We need to write joins select * from emp e join dept d on e.deptno = d.deptno Explicitly specify id column name select * from dept where id in (10, 20, 30)
  9. 9. Problems of JDBC JDBC  We need to do SQL to Java mappings setXXX(idx, value) ...well you know  We need to bind every variable in the SQL statement noted as ‘?’ otherwise exception occurs
  10. 10. Problems of JDBC JDBC  We need to do SQL to Java mappings setXXX(idx, value) ...well you know  We cannot run several queries select * from dept where deptno = 10, select * from emp where job = MGR
  11. 11. What’s about ORM? ORM (Hibernate)  We need to define class model and mapping
  12. 12. What’s about ORM? ORM (Hibernate)  We need to define class model and mapping  And we still need SQL (for advanced use) 
  13. 13. Agenda Motivation TreSQL vs SQL TreSQL statement structure Scala API
  14. 14. Sql vs TreSQL Simple SQL SQL: select * from dept
  15. 15. Sql vs TreSQL Simple SQL SQL: select * from dept TreSQL: dept
  16. 16. Sql vs TreSQL Select... Where SQL: select * from dept where deptno = 10
  17. 17. Sql vs TreSQL Select... Where SQL: select * from dept where deptno = 10 TreSQL: dept[10]
  18. 18. Sql vs TreSQL More complex select SQL: select deptno, dname from dept select ename from emp where deptno = :deptno
  19. 19. Sql vs TreSQL More complex select (needs programming when using SQL) SQL: select deptno, dname from dept select ename from emp where deptno = :deptno TreSQL: dept{deptno, dname, |emp[:1(1) = deptno] {ename} employees}
  20. 20. Sql vs TreSQL Multiple selects SQL: select * from dept where deptno = 10 select * from emp where job = MGR
  21. 21. Sql vs TreSQL Multiple selects SQL: select * from dept where deptno = 10 select * from emp where job = MGR‘ TreSQL: dept[10], emp[job = MGR]
  22. 22. Sql vs TreSQL Outer join order by SQL: select * from dept left join emp on dept.deptno = emp.deptno order by dname
  23. 23. Sql vs TreSQL Outer join order by SQL: select * from dept left join emp on dept.deptno = emp.deptno order by dname TreSQL: dept/emp? #(dname)
  24. 24. Sql vs TreSQL In, subselect SQL: select * from dept where deptno in (select deptno from emp)
  25. 25. Sql vs TreSQL In, subselect SQL: select * from dept where deptno in (select deptno from emp) TreSQL: dept [deptno in (emp{deptno})]
  26. 26. Sql vs TreSQL Exists, correlated subselect SQL: select * from dept d where exists select * from emp e where d.deptno = e.deptno
  27. 27. Sql vs TreSQL Exists, correlated subselect SQL: select * from dept d where exists select * from emp e where d.deptno = e.deptno TreSQL: dept d[(emp e[e.deptno = d.deptno])]
  28. 28. Sql vs TreSQL More complex example (using SQL programming is needed) dept{deptno, dname, |emp[sal >= hisal & sal <= losal]salgrade[deptno = :1(1)] {grade, hisal, losal, count(empno) empcount, |emp/dept[sal >= :1(2) & sal <= :1(3) & emp.deptno = :2(1)] {ename, emp.deptno, dname, sal}#(empno) emps } (grade, hisal, losal) #(1) salgrades } #(deptno)
  29. 29. Agenda Motivation TreSQL vs SQL TreSQL statement structure Scala API
  30. 30. TreSQL Language Structure SELECT statement structure <from>[<where>][<columns>][<group by> [<having>]][<order>][<offset> [<limit>]] table1[join cond]table2[where]{columns} (group cols)^(having expr) #(order) (offset limit)
  31. 31. TreSQL Language Structure INSERT DEPT {DEPTNO, DNAME, LOC} + [10, "ACCOUNTING", "NEW YORK"] Statement structure table {col1, col2} + [val1, val2]
  32. 32. TreSQL Language Structure UPDATE emp[1] {ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO} = [?, ?, ?, ?, ?, ?, ?] Statement structure table [where] {col1, col2} = [val1, val2]
  33. 33. TreSQL Language Structure DELETE emp - [1] Statement structure table - [where]
  34. 34. Agenda Motivation TreSQL vs SQL TreSQL statement structure Scala API
  35. 35. Scala API Code example:import org.tresql._Env update connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(0))}//val expr = Query.build("emp[deptno = ?]{*}")val result = expr.select(10)result foreach printlnexpr closeJsonizer.jsonize(Query(expr, pars), writer, rType)
  36. 36. Scala API Code example:import org.tresql._ org.tresql.Env Expression execution environment. Used for setting database connection.Env update connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(0))}//val expr = Query.build("emp[deptno = ?]{*}")val result = expr.select(10)result foreach printlnexpr close
  37. 37. Scala API Code example:import org.tresql._Env update connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(0))}// org.tresql.Query Expression execution, result iterationval expr = Query.build("emp[deptno = ?]{*}")val result = expr.select(10)result foreach printlnexpr close
  38. 38. Scala API Code example:import org.tresql._Env update connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(0))} org.tresql.Expr// Builded expression. Equivalent to java.sql.PreparedStatementval expr = Query.build("emp[deptno = ?]{*}")val result = expr.select(10)result foreach printlnexpr close
  39. 39. Scala API Code example:import org.tresql._Env update connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(0))}//val expr = Query.build("emp[deptno = ?]{*}")val result = expr.select(10) org.tresql.Exprresult foreach println Expression result – org.tresql.Resultexpr close
  40. 40. Scala API Code example:import org.tresql._org.tresql.Env update connectionorg.tresql.Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))}//val expr = Query.build("emp[deptno = ?]{*}")val result = expr.select(10) org.tresql.Exprresult foreach println Result JSON formattingexpr closeJsonizer.jsonize(Query(expr, pars), writer, rType)
  41. 41. Scala API Code example:import org.tresql._org.tresql.Env update connectionorg.tresql.Query.foreach("emp[sal > ? & deptno = ?]", 1000, 10) {row=> println(row(0))}org.tresql.Query.foreach("emp[sal > ? & deptno = ?]", 1000) {row=> println(row(0))} org.tresql.Expr Optional binding
  42. 42. That’s about it! Visit: https://github.com/mrumkovskis/Query
  43. 43. Q&A

×