C2FO / patio

Idiomatic database toolkit

Home Page:http://c2fo.github.io/patio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Explore cockroach db support

dustinsmith1024 opened this issue · comments

Just attempted a quick cockroach db connect and query. Initially it failed on the Postgres version check. I tweaked that function and queries started working.

Pushed to the cockroach branch. https://github.com/C2FO/patio/compare/cockroach?expand=1

var patio = require("../patio");

//set camelize = true if you want snakecase database columns as camelcase
patio.camelize = true;
// insecure mode password doesnt matter
const DB = patio.connect("cockroach://root:pass@127.0.0.1:26257/bank");
// console.log(DB);
const Accounts = patio.addModel("accounts");

// This works...
return DB.fetch("SELECT * FROM accounts").all().chain((data) => {
    console.log(data);
}).chain(() => {
    console.log("go sync")
return Accounts.sync().chain(() => {
        console.log('synced...')
    return Accounts.naked().all().chain((state) => {
        console.log(state);
    })
    .chain(process.exit, function (err) {
        console.log(err)
        process.exit(1);
    });
}, function(err) {
    console.log(err);
    process.exit();
});
});
➜ node test.js
[ { id: '1', balance: 1000.5 },
  { id: '2', balance: 2000.5 },
  { id: '3', balance: 222.5 },
  { id: '4', balance: 222.56 } ]
go sync
19.2.2
synced...
[ { id: '1', balance: 1000.5 },
  { id: '2', balance: 2000.5 },
  { id: '3', balance: 222.5 },
  { id: '4', balance: 222.56 } ]