Coder Social home page Coder Social logo

loicmahieu / knex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from knex/knex

0.0 3.0 0.0 10.47 MB

A query builder for PostgreSQL, MySQL and SQLite3, designed to be flexible, portable, and fun to use.

Home Page: knexjs.org

License: MIT License

JavaScript 91.95% HTML 7.96% Shell 0.09%

knex's Introduction

Gitter chat Gitter chat

A SQL query builder that is flexible, portable, and fun to use!

A batteries-included, multi-dialect (MySQL, PostgreSQL, SQLite3, WebSQL, Oracle) query builder for Node.js and the Browser, featuring:

Read the full documentation to get started!

For support and questions, join the #bookshelf channel on freenode IRC

For an Object Relational Mapper, see: http://bookshelfjs.org

Examples

We have several examples on the website. Here is the first one to get you started:

var knex = require('knex')({
  dialect: 'sqlite3',
  connection: {
    filename: './data.db'
  }
});

// Create a table
knex.schema.createTable('users', function(table) {
  table.increments('id');
  table.string('user_name');
})

// ...and another
.createTable('accounts', function(table) {
  table.increments('id');
  table.string('account_name');
  table.integer('user_id').unsigned().references('users.id');
})

// Then query the table...
.then(function() {
  return knex.insert({user_name: 'Tim'}).into('users');
})

// ...and using the insert id, insert into the other table.
.then(function(rows) {
  return knex.table('accounts').insert({account_name: 'knex', user_id: rows[0]});
})

// Query both of the rows.
.then(function() {
  return knex('users')
    .join('accounts', 'users.id', 'accounts.user_id')
    .select('users.user_name as user', 'accounts.account_name as account');
})

// .map over the results
.map(function(row) {
  console.log(row);
})

// Finally, add a .catch handler for the promise chain
.catch(function(e) {
  console.error(e);
});

knex's People

Contributors

tgriesser avatar bendrucker avatar vschoettke avatar nsantorello avatar calvinmetcalf avatar oohnoitz avatar benesch avatar zcei avatar kobalicek avatar vjpr avatar sohumb avatar nstepien avatar luigy avatar johanneslumpe avatar jblebrun avatar whitelynx avatar briandela avatar kchung avatar will123195 avatar wbyoung avatar ruifortes avatar ozum avatar sweetpi avatar demmer avatar lorenvs avatar blakeembrey avatar vvo avatar studds avatar oliverzy avatar tjbarber avatar

Watchers

James Cloos avatar Loïc Mahieu avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.