PHP Classes

File: test/js/test-redis.js

Recommend this page to a friend!
  Classes of Nikos M.   Dialect PHP ORM and ODM Library   test/js/test-redis.js   Download  
File: test/js/test-redis.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Dialect PHP ORM and ODM Library
Store and retrieve objects in database using ORM
Author: By
Last change: v.2.0.1

* fix some typos that remained
* update Dialect and tests
Date: 4 months ago
Size: 1,143 bytes
 

Contents

Class file image Download
"use strict"; const DialectORM = require('../../src/js/DialectORM.js'); const RedisStorage = require('./nosql/redis.js')(DialectORM.NoSql); DialectORM.NoSql.NoSqlHandler(new RedisStorage({ 'host' : '127.0.0.1', 'port' : 6379, 'namespace' : 'dialectorm:' })); class Tweet extends DialectORM.NoSql { static collection = 'tweets'; static pk = ['id']; typeId(x) { return parseInt(x, 10); } typeContent(x) { return String(x); } validateContent(x) { return 0 < x.length; } } function print(x) { console.log(x); } function output(data) { if (Array.isArray(data)) print(JSON.stringify(data.map(d => d.toObj()), null, 4)); else if (data instanceof DialectORM.NoSql) print(JSON.stringify(data.toObj(), null, 4)); else print(String(data)); } async function test() { output(await Tweet.fetchByPk(2)); //let tweet = new Tweet({'content' : 'hello redis2!'}); //tweet.setId(2); //await tweet.save(); output(await Tweet.fetchByPk(2)); } test().then(() => process.exit()).catch(e => {print(e); process.exit();});