Comparing version 0.0.5 to 0.1.0
@@ -132,3 +132,8 @@ var From = require(__dirname + '/../node/from'); | ||
var table = tableNode.table; | ||
var txt = this.quote(table.getName()); | ||
var txt=""; | ||
if(table.getSchema()) { | ||
txt = this.quote(table.getSchema()); | ||
txt += '.' | ||
} | ||
txt += this.quote(table.getName()); | ||
if(table.alias) { | ||
@@ -147,3 +152,7 @@ txt += ' AS ' + table.alias; | ||
} else { | ||
txt = this.quote(table.getName()); | ||
if(table.getSchema()) { | ||
txt = this.quote(table.getSchema()); | ||
txt += '.'; | ||
} | ||
txt += this.quote(table.getName()); | ||
} | ||
@@ -150,0 +159,0 @@ txt += '.' |
@@ -8,2 +8,3 @@ var Query = require(__dirname + '/node/query'); | ||
var Table = function(config) { | ||
this._schema = config.schema; | ||
this._name = config.name; | ||
@@ -37,2 +38,6 @@ this._initialConfig = config; | ||
Table.prototype.getSchema = function() { | ||
return this._schema; | ||
} | ||
Table.prototype.getName = function() { | ||
@@ -39,0 +44,0 @@ return this._name; |
@@ -5,3 +5,3 @@ { | ||
"description": "sql builder", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/brianc/node-sql", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -29,3 +29,3 @@ var tap = require('tap').test; | ||
query : user.select(user.id).from(user), | ||
pg : 'SELECT "user".id FROM "user"' | ||
pg : 'SELECT "user"."id" FROM "user"' | ||
}); | ||
@@ -35,3 +35,3 @@ | ||
query : user.select(user.id, user.name).from(user), | ||
pg : 'SELECT "user".id, "user".name FROM "user"' | ||
pg : 'SELECT "user"."id", "user"."name" FROM "user"' | ||
}); | ||
@@ -46,3 +46,3 @@ | ||
query : user.select(user.id).from(user).where(user.name.equals('foo')), | ||
pg : 'SELECT "user".id FROM "user" WHERE ("user".name = $1)', | ||
pg : 'SELECT "user"."id" FROM "user" WHERE ("user"."name" = $1)', | ||
params: ['foo'] | ||
@@ -53,3 +53,3 @@ }); | ||
query : user.select(user.id).from(user).where(user.name.equals('foo').or(user.name.equals('bar'))), | ||
pg : 'SELECT "user".id FROM "user" WHERE (("user".name = $1) OR ("user".name = $2))', | ||
pg : 'SELECT "user"."id" FROM "user" WHERE (("user"."name" = $1) OR ("user"."name" = $2))', | ||
params: ['foo', 'bar'] | ||
@@ -60,3 +60,3 @@ }); | ||
query : user.select(user.id).from(user).where(user.name.equals('foo').and(user.name.equals('bar'))), | ||
pg : 'SELECT "user".id FROM "user" WHERE (("user".name = $1) AND ("user".name = $2))', | ||
pg : 'SELECT "user"."id" FROM "user" WHERE (("user"."name" = $1) AND ("user"."name" = $2))', | ||
params: ['foo', 'bar'] | ||
@@ -67,3 +67,3 @@ }); | ||
query : user.select(user.id).from(user).where(user.name.equals('foo')).or(user.name.equals('bar')), | ||
pg : 'SELECT "user".id FROM "user" WHERE (("user".name = $1) OR ("user".name = $2))' | ||
pg : 'SELECT "user"."id" FROM "user" WHERE (("user"."name" = $1) OR ("user"."name" = $2))' | ||
}); | ||
@@ -73,3 +73,3 @@ | ||
query : user.select(user.id).from(user).where(user.name.equals('foo')).or(user.name.equals('baz')).and(user.name.equals('bar')), | ||
pg : 'SELECT "user".id FROM "user" WHERE ((("user".name = $1) OR ("user".name = $2)) AND ("user".name = $3))' | ||
pg : 'SELECT "user"."id" FROM "user" WHERE ((("user"."name" = $1) OR ("user"."name" = $2)) AND ("user"."name" = $3))' | ||
}); | ||
@@ -81,3 +81,3 @@ | ||
.and(user.id.equals(1))).or(user.name.equals('bang').and(user.id.equals(2))), | ||
pg : 'SELECT "user".id FROM "user" WHERE ((("user".name = $1) AND ("user".id = $2)) OR (("user".name = $3) AND ("user".id = $4)))' | ||
pg : 'SELECT "user"."id" FROM "user" WHERE ((("user"."name" = $1) AND ("user"."id" = $2)) OR (("user"."name" = $3) AND ("user"."id" = $4)))' | ||
}); | ||
@@ -92,3 +92,3 @@ | ||
query : user.select(user.name, post.content).from(user.join(post).on(user.id.equals(post.userId))), | ||
pg : 'SELECT "user".name, post.content FROM "user" INNER JOIN post ON ("user".id = post."userId")' | ||
pg : 'SELECT "user"."name", "post"."content" FROM "user" INNER JOIN "post" ON ("user"."id" = "post"."userId")' | ||
}); | ||
@@ -99,3 +99,3 @@ | ||
query : u.select(u.name).from(u), | ||
pg :'SELECT u.name FROM "user" AS u' | ||
pg :'SELECT u."name" FROM "user" AS u' | ||
}); | ||
@@ -106,3 +106,3 @@ | ||
query : u.select(u.name).from(u.join(p).on(u.id.equals(p.userId).and(p.id.equals(3)))), | ||
pg : 'SELECT u.name FROM "user" AS u INNER JOIN post AS p ON ((u.id = p."userId") AND (p.id = $1))' | ||
pg : 'SELECT u."name" FROM "user" AS u INNER JOIN "post" AS p ON ((u."id" = p."userId") AND (p."id" = $1))' | ||
}); | ||
@@ -112,3 +112,3 @@ | ||
query : u.select(p.content, u.name).from(u.join(p).on(u.id.equals(p.userId).and(p.content.isNotNull()))), | ||
pg : 'SELECT p.content, u.name FROM "user" AS u INNER JOIN post AS p ON ((u.id = p."userId") AND (p.content IS NOT NULL))' | ||
pg : 'SELECT p."content", u."name" FROM "user" AS u INNER JOIN "post" AS p ON ((u."id" = p."userId") AND (p."content" IS NOT NULL))' | ||
}); | ||
@@ -123,3 +123,3 @@ | ||
query : post.select(post.content), | ||
pg : 'SELECT post.content FROM post' | ||
pg : 'SELECT "post"."content" FROM "post"' | ||
}); | ||
@@ -129,3 +129,3 @@ | ||
query : post.select(post.content).where(post.userId.equals(1)), | ||
pg : 'SELECT post.content FROM post WHERE (post."userId" = $1)' | ||
pg : 'SELECT "post"."content" FROM "post" WHERE ("post"."userId" = $1)' | ||
}); | ||
@@ -136,3 +136,3 @@ | ||
query : post.select(post.content).order(post.content), | ||
pg : 'SELECT post.content FROM post ORDER BY post.content', | ||
pg : 'SELECT "post"."content" FROM "post" ORDER BY "post"."content"', | ||
}); | ||
@@ -142,3 +142,3 @@ | ||
query : post.select(post.content).order(post.content, post.userId.descending), | ||
pg : 'SELECT post.content FROM post ORDER BY post.content, (post."userId" DESC)' | ||
pg : 'SELECT "post"."content" FROM "post" ORDER BY "post"."content", ("post"."userId" DESC)' | ||
}); | ||
@@ -148,3 +148,3 @@ | ||
query : post.select(post.content).order(post.content.asc, post.userId.desc), | ||
pg : 'SELECT post.content FROM post ORDER BY post.content, (post."userId" DESC)' | ||
pg : 'SELECT "post"."content" FROM "post" ORDER BY "post"."content", ("post"."userId" DESC)' | ||
}); | ||
@@ -155,3 +155,3 @@ | ||
query : post.insert(post.content.value('test'), post.userId.value(1)), | ||
pg : 'INSERT INTO post (content, "userId") VALUES ($1, $2)', | ||
pg : 'INSERT INTO "post" ("content", "userId") VALUES ($1, $2)', | ||
params: ['test', 1] | ||
@@ -162,3 +162,3 @@ }); | ||
query : post.insert(post.content.value('whoah')), | ||
pg : 'INSERT INTO post (content) VALUES ($1)', | ||
pg : 'INSERT INTO "post" ("content") VALUES ($1)', | ||
params: ['whoah'] | ||
@@ -169,3 +169,3 @@ }); | ||
query : post.insert({content: 'test', userId: 2}), | ||
pg : 'INSERT INTO post (content, "userId") VALUES ($1, $2)', | ||
pg : 'INSERT INTO "post" ("content", "userId") VALUES ($1, $2)', | ||
params: ['test', 2] | ||
@@ -177,3 +177,3 @@ }); | ||
query : post.update({content: 'test'}), | ||
pg : 'UPDATE post SET post.content = $1', | ||
pg : 'UPDATE "post" SET "content" = $1', | ||
params: ['test'] | ||
@@ -184,3 +184,3 @@ }); | ||
query : post.update({content: 'test', userId: 3}), | ||
pg : 'UPDATE post SET post.content = $1, post."userId" = $2', | ||
pg : 'UPDATE "post" SET "content" = $1, "userId" = $2', | ||
params: ['test', 3] | ||
@@ -191,3 +191,3 @@ }); | ||
query : post.update({content: 'test', userId: 3}).where(post.content.equals('no')), | ||
pg : 'UPDATE post SET post.content = $1, post."userId" = $2 WHERE (post.content = $3)', | ||
pg : 'UPDATE "post" SET "content" = $1, "userId" = $2 WHERE ("post"."content" = $3)', | ||
params: ['test', 3, 'no'] | ||
@@ -198,3 +198,3 @@ }); | ||
query : post.delete().where(post.content.equals('')), | ||
pg : 'DELETE FROM post WHERE (post.content = $1)', | ||
pg : 'DELETE FROM "post" WHERE ("post"."content" = $1)', | ||
params: [''] | ||
@@ -205,6 +205,6 @@ }); | ||
var parent = post.select(post.content); | ||
assert.textEqual(parent, 'SELECT post.content FROM post'); | ||
assert.textEqual(parent, 'SELECT "post"."content" FROM "post"'); | ||
var child = parent.select(post.userId).where(post.userId.equals(1)); | ||
assert.textEqual(parent, 'SELECT post.content FROM post'); | ||
assert.textEqual(child, 'SELECT post.content, post."userId" FROM post WHERE (post."userId" = $1)'); | ||
assert.textEqual(parent, 'SELECT "post"."content" FROM "post"'); | ||
assert.textEqual(child, 'SELECT "post"."content", "post"."userId" FROM "post" WHERE ("post"."userId" = $1)'); | ||
} | ||
@@ -225,3 +225,42 @@ | ||
query : comment.select(comment.text, comment.userId), | ||
pg : 'SELECT comment."text", comment.userId FROM comment', | ||
pg : 'SELECT "comment"."text", "comment"."userId" FROM "comment"', | ||
}); | ||
var userWithSchema = Table.define({ | ||
schema: 'staging', | ||
name: 'user', | ||
quote: true, | ||
columns: ['id','name'] | ||
}) | ||
test({ | ||
query : userWithSchema.select(userWithSchema.id).from(userWithSchema), | ||
pg : 'SELECT "staging"."user"."id" FROM "staging"."user"' | ||
}); | ||
test({ | ||
query : userWithSchema.select(userWithSchema.id, userWithSchema.name).from(userWithSchema), | ||
pg : 'SELECT "staging"."user"."id", "staging"."user"."name" FROM "staging"."user"' | ||
}); | ||
var uws = userWithSchema.as('uws'); | ||
test({ | ||
query : uws.select(uws.name).from(uws), | ||
pg :'SELECT uws."name" FROM "staging"."user" AS uws' | ||
}); | ||
var postWithSchema = Table.define({ | ||
schema: 'dev', | ||
name: 'post', | ||
columns: ['id', 'userId', 'content'] | ||
}); | ||
test({ | ||
query : userWithSchema.select(userWithSchema.name, postWithSchema.content).from(userWithSchema.join(postWithSchema).on(userWithSchema.id.equals(postWithSchema.userId))), | ||
pg : 'SELECT "staging"."user"."name", "dev"."post"."content" FROM "staging"."user" INNER JOIN "dev"."post" ON ("staging"."user"."id" = "dev"."post"."userId")' | ||
}); | ||
test({ | ||
query : uws.select(uws.name, postWithSchema.content).from(uws.join(postWithSchema).on(uws.id.equals(postWithSchema.userId))), | ||
pg : 'SELECT uws."name", "dev"."post"."content" FROM "staging"."user" AS uws INNER JOIN "dev"."post" ON (uws."id" = "dev"."post"."userId")' | ||
}); |
@@ -28,5 +28,5 @@ var test = require('tap').test; | ||
var query = sql.select(user.id).from(user).where(user.email.equals('brian.m.carlson@gmail.com')).toQuery(); | ||
t.equal(query.text, 'SELECT user.id FROM user WHERE (user.email = $1)'); | ||
t.equal(query.text, 'SELECT "user"."id" FROM "user" WHERE ("user"."email" = $1)'); | ||
t.equal(query.values[0], 'brian.m.carlson@gmail.com') | ||
t.end(); | ||
}); |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
27975
859
0