From 60cfe17204ce8c5c8e1c1c217f45be7ae10bbc74 Mon Sep 17 00:00:00 2001 From: "fabio.soares" Date: Fri, 29 Dec 2017 02:43:35 -0200 Subject: [PATCH 1/2] inconplete --- README.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1a3af8c..a6a83d7b 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ var sql = require('sql'); //(optionally) set the SQL dialect sql.setDialect('postgres'); -//possible dialects: mssql, mysql, postgres (default), sqlite +//possible dialects: mssql, mysql, postgres (default), oracle and sqlite //first we define our tables var user = sql.define({ @@ -108,6 +108,33 @@ console.log(user.select().where(user.state.equals('WA')).toQuery().text); // "SELECT "user".* FROM "user" WHERE ("user"."state_or_province" = $1)" ``` +### CURD Example + +```js +// Create + +let query = model + .insert( + model.name.value(user.name), + model.username.value(user.username), + model.password.value(user.password), + model.client.value(user.client), + model.email.value(user.email), + model.created_at.value(new Date()) + ) + .toQuery(); + //read + let query = model.select(model.star()) + .where(user) + .toQuery(); +//update +let query = model.update(user).where(model.username.equals(user.username)).toQuery(); +//delete +model.delete() + .where(model.email.equals('test3@test.com').or(model.email.equals('test4@test.com'))) + .toQuery(); +``` + There are a __lot__ more examples included in the [test/dialects](https://github.com/brianc/node-sql/tree/master/test/dialects) folder. We encourage you to read through them if you have any questions on usage! ## from the command line From 3c2140c5f99b5fa8cdc521f1b72b1c92bf53ed23 Mon Sep 17 00:00:00 2001 From: "fabio.soares" Date: Sat, 30 Dec 2017 00:23:10 -0200 Subject: [PATCH 2/2] reviewing alterations --- README.md | 53 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index a6a83d7b..072c836a 100644 --- a/README.md +++ b/README.md @@ -111,31 +111,42 @@ console.log(user.select().where(user.state.equals('WA')).toQuery().text); ### CURD Example ```js +const sql = require('sql'); +sql.setDialect('oracle'); +const user = sql.define({ + name: 'user', + columns: ['name', 'username', 'email'] +}); // Create +let create = user.insert({name: 'Name', email: 'teste@test.com'}).toQuery(); + +console.log(create.text); +// "INSERT INTO "user" ("name", "email") VALUES (:1, :2)" + +// Read +let read = user.select(user.star()).where(user.name.equals("Test")).toQuery(); + +console.log(read.text); +// "SELECT "user".* FROM "user" WHERE ("user"."name" = :1) + +// Update +let update = user.update({email: 'test0@test.com', username: 'teste-user'}) +.where(user.email.equals('test@test.com').or(user.email.equals('test@test.com'))).toQuery(); + +console.log(update.text); +// "UPDATE "user" SET "email" = :1, "username" = :2 WHERE ("user"."email" = :3)" + +// Delete +let deleteUser = user.delete().where({username: 'test'}).toQuery(); -let query = model - .insert( - model.name.value(user.name), - model.username.value(user.username), - model.password.value(user.password), - model.client.value(user.client), - model.email.value(user.email), - model.created_at.value(new Date()) - ) - .toQuery(); - //read - let query = model.select(model.star()) - .where(user) - .toQuery(); -//update -let query = model.update(user).where(model.username.equals(user.username)).toQuery(); -//delete -model.delete() - .where(model.email.equals('test3@test.com').or(model.email.equals('test4@test.com'))) - .toQuery(); +console.log(deleteUser.text); +// "DELETE FROM "user" WHERE ("user"."username" = :1)" ``` +## More examples: -There are a __lot__ more examples included in the [test/dialects](https://github.com/brianc/node-sql/tree/master/test/dialects) folder. We encourage you to read through them if you have any questions on usage! +There are a __lot__ more examples included in the [test/dialects](https://github.com/brianc/node-sql/tree/master/test/dialects) folder and on +[node-sql-examples.github.io](https://node-sql-examples.github.io). +We encourage you to read through them if you have any questions on usage! ## from the command line You can use the [sql-generate module](https://github.com/tmont/node-sql-generate)