persvr / perstore

CommonJS persistence/object storage based on W3C's object store API.
http://www.persvr.org/
96 stars 20 forks source link

mySQL support non-functional. #3

Open Trakkasure opened 14 years ago

Trakkasure commented 14 years ago

Error thrown when executing a simple test script exclaims that mysql_bindings is missing: nodules

node.js:50 throw e; ^ Error: Cannot find module 'node-mysql-libmysqlclient/mysql_bindings' at loadModule (node.js:234:13) at require (node.js:272:14) at /usr/local/lib/node/.npm/nodules/0.2.1/package/lib/nodules.js:266:32 at Object. (file://../node-mysql-libmysqlclient/mysql-libmysqlclient.js:13:15) at /usr/local/lib/node/.npm/nodules/0.2.1/package/lib/nodules.js:236:23 at jar:http://github.com/kriszyp/perstore/zipball/v0.2.1!/engines/node/lib/store-engine/sql.js:19:9 at Object.defaultDatabase (jar:http://github.com/kriszyp/perstore/zipball/v0.2.1!/lib/store/sql.js:262:20) at Object.SQLStore (jar:http://github.com/kriszyp/perstore/zipball/v0.2.1!/lib/store/sql.js:30:44) at Object. (file:///build/nodeTest/lib/index.js:5:43) at /usr/local/lib/node/.npm/nodules/0.2.1/package/lib/nodules.js:236:23

Example is mostly copied and pasted from existing example.

var store = require("perstore/store/sql").SQLStore({
type: "mysql",
table: "user",
idColumn: "id"
});

// now we can setup a model that wraps the data store var MyModel = require("perstore/model").Model("User", store, { properties: { // we can define optionally define type constraints on properties id: Integer, name: String } }); var someObject = MyModel.new(); // retrieve a persisted object someObject.id = 1; // make a change someObject.name = "Trakkasure"; // make a change someObject.save(); // and save it

kriszyp commented 14 years ago

You need to compile the mysql_bindings with node-waf (and make sure it is in an accessible location as a module).

Trakkasure commented 14 years ago

Will this work given that perstore performs a require directly on the mysql-libmysqlclient downloaded from github? (even if I want to use a different one I compiled myself):

myConn = require("jar:http://github.com/Sannis/node-mysql-libmysqlclient/zipball/master!/mysql-libmysqlclient.js")

I downloaded, and installed mysql-libmysqlclient using npm. mysql_bindings.node does exist in /usr/local/lib/node/mysql-libmysqlclient. And /usr/local/lib/node is in my NODE_PATH

I am assuming I should move mysql_bindings.node into /usr/local/lib/node

Trakkasure commented 14 years ago

So I pulled everything. The error now is ( and I hope this clears things up...) Cannot find module 'downloaded-modules/github.com/Sannis/node-mysql-libmysqlclient/zipball/master/mysql_bindings

I have the mysql_bindings.node file installed everywhere I could think. My head is swimming with tons of new concepts. I can only assume that this is related to using nodules to execute my test. I have always been able to run other tests connecting to a DB and executing a query using mysql-libmysqlclient without nodules.

It seems to be related. I'm no expert or anything. Most of the docs I have been able to find need updating in some form or another (examples, or getting started - pentura says just copy the templates directory... but none are found in the repo). I am really interested in utilizing this framework, so any help getting the basics out of the way would be greatly appreciated.

kriszyp commented 14 years ago

It looks like http://github.com/Sannis/node-mysql-libmysqlclient/commit/49cc3db493b6caa431fe38abcf257192d711da0e is the problem, apparently there is some crazy module lookup that makes no sense now. I would change the file back to using a simple require("./mysql_bindings") or require("mysql_bindings") if you put mysql_bindings in /usr/local/lib/node.

Trakkasure commented 14 years ago

That also does not resolve the issue since the ./ implies that mysql_bindings resides in the same place as the mysql .js file. In this case, the zipball downloaded by nodules does not contain the bindings file... which is correct since it needs to be compiled for each target system.

If I change the sql.js file: engines/node/lib/store-engine/sql.js: myConn = require("mysql-libmysqlclient/mysql-libmysqlclient") and then change the mysql-libmysqlclient mapping from the package it does not work. Removing it from the package.json and changing to require("mysql-libmysqlclient") also does not work (it should find it in /usr/local/lib/node/mysql-libmysqlclient/index.js) It seems that NODULES is incompatible with NPM installed modules.. or modules found in NODE_PATH. Is this by design, or a side-effect?

Trakkasure commented 14 years ago

If you have a chance, could you walk though a simple example of successfully using perstore with a mySQL database, starting from a fresh install of node, mysql-libmysqlclient and nodules from npm, and nothing else. It may make things more clear to me, or may bring to light a possible bug. I really like how nodules keeps things tidy to specify package distributions, but it seems silly to have to download packages that you may already have.

bronson commented 12 years ago

I have the same problem. It's because the build drops the binary in build/default/mysql_bindings.node. If you cp that to the root dir, node will be able to find it. No idea how this works for other people.

cp node_modules/mysql-libmysqlclient/build/default/mysql_bindings.node node_modules/mysql-libmysqlclient