models.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const { Store, Cache } = require('ringo-sqlstore');
  2. // create and configure store
  3. const connectionPool = module.singleton("connectionPool", function () {
  4. const mysqlConnectionProperties = "?jdbcCompliantTruncation=false&elideSetAutoCommits=true&useLocalSessionState=true&cachePrepStmts=true&cacheCallableStmts=true&alwaysSendSetIsolation=false&prepStmtCacheSize=4096&cacheServerConfiguration=true&prepStmtCacheSqlLimit=2048&zeroDateTimeBehavior=convertToNull&traceProtocol=false&useServerPrepStmts=true&enableQueryTimeouts=false&useUnbufferedIO=false&useReadAheadInput=false&maintainTimeStats=false&cacheRSMetadata=true&useSSL=false";
  5. return Store.initConnectionPool({
  6. "url": "jdbc:mysql://tfb-database/hello_world" + mysqlConnectionProperties,
  7. // This is not the correct driver but it is used as a workaround.
  8. // The library ringo-sqlstore needs updating
  9. "driver": "com.mysql.jdbc.Driver",
  10. "username": "benchmarkdbuser",
  11. "password": "benchmarkdbpass",
  12. "minimumIdle": 10,
  13. "maximumPoolSize": 30
  14. });
  15. });
  16. const store = exports.store = new Store(connectionPool);
  17. const queryCache = module.singleton("queryCache", function () {
  18. return new Cache(10000);
  19. });
  20. store.setQueryCache(queryCache);
  21. // define entities in DB
  22. exports.World = store.defineEntity('World', {
  23. table: 'World',
  24. id: {
  25. column: 'id'
  26. },
  27. properties: {
  28. randomNumber: 'integer'
  29. }
  30. });
  31. const Fortune = exports.Fortune = store.defineEntity('Fortune', {
  32. table: 'Fortune',
  33. properties: {
  34. message: 'string'
  35. }
  36. });
  37. Fortune.sort = function (a, b) {
  38. return (a.message < b.message) ? -1 : (a.message > b.message) ? 1 : 0;
  39. };