Name |
Ceylon Database Platform Module |
---|---|
Category |
SDK
The Ceylon SDK |
Backends | JVM |
Maven coordinates | |
Compatible Ceylon release |
JVM: 1.1.0 (outdated) |
Published | Oct 8, 2014 |
Stats |
Downloads (JVM): 705 Source downloads: 724 |
Authors |
Enrique Zamudio |
License | Apache Software License 2.0 |
Description |
This module offers some components for JDBC-based
database connectivity. The main component is the class
value sql = Sql(newConnectionFromDataSource(dataSource)); You can easily get a query result as a value rows = sql.Select("select * from mytable").execute(); for (row in rows) { assert (is String name = rows["name"]); assert (is Integer count = rows["count"]); ... } You can define parameters to the query, using the value rows = sql.Select("select * from mytable where col1=? and col2=?") .execute(arg1, arg2); The try (results = sql.Select("select * from mytable where date>?") .Results(date)) { results.limit = 50; for (row in results) { ... } } Alternatively, sql.Select("select * from mytable where date>?") .forEachRow(date)((row) { ... }); A value query = sql.Select("select * from mytable where col=?"); value result1 = query.execute(value1); value result2 = query.execute(value2); And of course you can execute sql.Update("update table SET col=? where key=?") .execute(newValue, key); sql.Insert("insert into table (key,col) values (?, ?)") .execute(key, initialValue); If you need to perform several operations within a single
transaction, you can pass a function to the method
sql.transaction { function do() { sql.Insert("insert ... ").execute(); sql.Update("update ... ").execute(); sql.Update("delete ... ").execute(); //return true to commit the transaction //return false or throw to roll it back return true; } }; To pass a null value as an argument, use a sql.Update("update table set col=? where key=?") .execute(SqlNull(Types.\iINTEGER)); If a column is null on a result row, it will be
represented as a |
Dependencies |
ceylon.math/1.1.0
shared
java.base/7 JDK
java.jdbc/7 JDK
shared
|
Usage |
import ceylon.dbc "1.1.0"; |
Module links |
Members Imported By Home Code repository Issue tracker Browse Download .car No .js archive Download source archive Download module documentation View API documentation |