models.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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&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. "driver": "com.mysql.jdbc.Driver",
  8. "username": "benchmarkdbuser",
  9. "password": "benchmarkdbpass",
  10. "minimumIdle": 10,
  11. "maximumPoolSize": 30
  12. });
  13. });
  14. const store = exports.store = new Store(connectionPool);
  15. const queryCache = module.singleton("queryCache", function() {
  16. return new Cache(10000);
  17. });
  18. store.setQueryCache(queryCache);
  19. // define entities in DB
  20. exports.World = store.defineEntity('World', {
  21. table: 'World',
  22. id: {
  23. column: 'id'
  24. },
  25. properties: {
  26. randomNumber: 'integer'
  27. }
  28. });
  29. const Fortune = exports.Fortune = store.defineEntity('Fortune', {
  30. table: 'Fortune',
  31. properties: {
  32. message: 'string'
  33. }
  34. });
  35. Fortune.sort = function(a, b) {
  36. return (a.message < b.message) ? -1 : (a.message > b.message) ? 1 : 0;
  37. };