Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: horizon_server._reql_conn.read is not a function #848

Open
vignestion opened this issue Oct 2, 2016 · 3 comments
Open

TypeError: horizon_server._reql_conn.read is not a function #848

vignestion opened this issue Oct 2, 2016 · 3 comments

Comments

@vignestion
Copy link

How to use reql embed quries with horizon

horizon_server._reql_conn.read().then((reql_conn) => {
                          ^


const express = require('express');
const https = require('https');
const path = require('path');
const fs = require('fs');
const horizon = require('@horizon/server');
const r = horizon.r;

const app = express();

// Serve our static stuff like css
app.use(express.static(path.join(__dirname, 'dist')));

// Send all requests to index.html
app.get('*', function (req, res) {
    res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});
const options = {
    key: fs.readFileSync(path.resolve(__dirname, './horizon-key.pem')),
    cert: fs.readFileSync(path.resolve(__dirname, './horizon-cert.pem')),
};

const PORT = 8181;

const server = https.createServer(options, app);

server.listen(PORT, function() {
    console.log('Express server running at localhost:' + PORT);
});

const horizon_options = {
    project_name: 'react_horizon',
    permissions: false,

    auth: {
        token_secret:  'sd',
        allow_anonymous: true,
        allow_unauthenticated: true,

    }
};
const horizon_server = horizon(server, horizon_options);
//error 
horizon_server._reql_conn.read().then((reql_conn) => {
    var doc = r.db('react_horizon').table('views').get(2).run(reql_conn.connection());
    console.log(doc)
});

@jirikolarik
Copy link

Hey, something like that wouldn't work?

const connection =  horizon_server._reql_conn.connection();
horizon.r.db('database').table('..').customQuery.run(connection);

@MichalZalecki
Copy link

MichalZalecki commented Oct 9, 2016

@jirikolarik Not quite

Error: Connection to the database is down.

@githubitsme Try _ready_promise instead of read().

horizonServer._reql_conn._ready_promise.then((reql_conn) => {

@jirikolarik
Copy link

jirikolarik commented Mar 5, 2017

I got it working like this:

horizonServer._reql_conn.ready().then(() => { // eslint-disable-line no-underscore-dangle
  const conn = horizonServer._reql_conn.connection();
  horizon.r.db('database').table('..').customQuery.run(connection);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants