Black Lives Matter. Support the Equal Justice Initiative.

Bu dok├╝man ingilizce dok├╝mana g├Âre eski olabilir. Son g├╝ncellemeler i├žin l├╝tfen ─░ngilizce Dok├╝man─▒. ziyaret edin

Ôťľ

Veritaban─▒ integrasyonu

Veritabanlar─▒n─▒ Express uygulamalar─▒na ba─člama kabiliyeti eklemek, uygulaman─▒zdaki veritaban─▒ i├žin uygun bir Node.js s├╝r├╝c├╝s├╝n├╝ y├╝kleyerek yap─▒labilecek kadar kolayd─▒r. Bu d├Âk├╝man, Express uygulaman─▒za veritaban─▒ sistemleri i├žin baz─▒ pop├╝ler Node.js mod├╝llerinin nas─▒l eklendi─čini ve kullan─▒ld─▒─č─▒n─▒ k─▒saca anlat─▒r:

Bu veritaban─▒ s├╝r├╝c├╝leri mevcut olanlar─▒n ├žo─čunun aras─▒ndad─▒r. Di─čer se├ženekler i├žin, npm sitesinde aray─▒n─▒z.

Cassandra

Module: cassandra-driver

Y├╝kleme

$ npm install cassandra-driver

├ľrnek

var cassandra = require('cassandra-driver')
var client = new cassandra.Client({ contactPoints: ['localhost'] })

client.execute('select key from system.local', function (err, result) {
  if (err) throw err
  console.log(result.rows[0])
})

Couchbase

Module: couchnode

Y├╝kleme

$ npm install couchbase

├ľrnek

var couchbase = require('couchbase')
var bucket = (new couchbase.Cluster('http://localhost:8091')).openBucket('bucketName')

// bir d├Âk├╝man─▒ bir kovaya ekle
bucket.insert('document-key', { name: 'Matt', shoeSize: 13 }, function (err, result) {
  if (err) {
    console.log(err)
  } else {
    console.log(result)
  }
})

// "shoe" alan─▒n─▒n de─čeri 13 olan b├╝t├╝n d├Âk├╝manlar─▒ getir
var n1ql = 'SELECT d.* FROM `bucketName` d WHERE shoeSize = $1'
var query = N1qlQuery.fromString(n1ql)
bucket.query(query, [13], function (err, result) {
  if (err) {
    console.log(err)
  } else {
    console.log(result)
  }
})

CouchDB

Module: nano

Y├╝kleme

$ npm install nano

├ľrnek

var nano = require('nano')('http://localhost:5984')
nano.db.create('books')
var books = nano.db.use('books')

// books veritaban─▒na bir kitap ekle
books.insert({ name: 'The Art of war' }, null, function (err, body) {
  if (err) {
    console.log(err)
  } else {
    console.log(body)
  }
})

// b├╝t├╝n kitaplar─▒n bir listesini getir
books.list(function (err, body) {
  if (err) {
    console.log(err)
  } else {
    console.log(body.rows)
  }
})

LevelDB

Module: levelup

Y├╝kleme

$ npm install level levelup leveldown

├ľrnek

var levelup = require('levelup')
var db = levelup('./mydb')

db.put('name', 'LevelUP', function (err) {
  if (err) return console.log('Ooops!', err)

  db.get('name', function (err, value) {
    if (err) return console.log('Ooops!', err)

    console.log('name=' + value)
  })
})

MySQL

Module: mysql

Y├╝kleme

$ npm install mysql

├ľrnek

var mysql = require('mysql')
var connection = mysql.createConnection({
  host: 'localhost',
  user: 'dbuser',
  password: 's3kreee7',
  database: 'my_db'
})

connection.connect()

connection.query('SELECT 1 + 1 AS solution', function (err, rows, fields) {
  if (err) throw err

  console.log('The solution is: ', rows[0].solution)
})

connection.end()

MongoDB

Module: mongodb

Y├╝kleme

$ npm install mongodb

├ľrnek (v2.*)

var MongoClient = require('mongodb').MongoClient

MongoClient.connect('mongodb://localhost:27017/animals', function (err, db) {
  if (err) throw err

  db.collection('mammals').find().toArray(function (err, result) {
    if (err) throw err

    console.log(result)
  })
})

├ľrnek (v3.*)

var MongoClient = require('mongodb').MongoClient

MongoClient.connect('mongodb://localhost:27017/animals', function (err, client) {
  if (err) throw err

  var db = client.db('animals')

  db.collection('mammals').find().toArray(function (err, result) {
    if (err) throw err

    console.log(result)
  })
})

MongoDB i├žin bir nesne model s├╝r├╝c├╝s├╝ istiyorsan─▒z, bak─▒n─▒z Mongoose.

Neo4j

Module: apoc

Y├╝kleme

$ npm install apoc

├ľrnek

var apoc = require('apoc')

apoc.query('match (n) return n').exec().then(
  function (response) {
    console.log(response)
  },
  function (fail) {
    console.log(fail)
  }
)

Oracle

Module: oracledb

Y├╝kleme

NOTE: Y├╝kleme ├Ânko┼čullar─▒ i├žin bak─▒n─▒z.

$ npm install oracledb

├ľrnek

const oracledb = require('oracledb')
const config = {
  user: '<your db user>',
  password: '<your db password>',
  connectString: 'localhost:1521/orcl'
}

async function getEmployee (empId) {
  let conn

  try {
    conn = await oracledb.getConnection(config)

    const result = await conn.execute(
      'select * from employees where employee_id = :id',
      [empId]
    )

    console.log(result.rows[0])
  } catch (err) {
    console.log('Ouch!', err)
  } finally {
    if (conn) { // conn g├Ârevi ├žal─▒┼čt─▒, kapat─▒lmal─▒
      await conn.close()
    }
  }
}

getEmployee(101)

PostgreSQL

Module: pg-promise

Y├╝kleme

$ npm install pg-promise

├ľrnek

var pgp = require('pg-promise')(/* se├ženekler */)
var db = pgp('postgres://username:password@host:port/database')

db.one('SELECT $1 AS value', 123)
  .then(function (data) {
    console.log('DATA:', data.value)
  })
  .catch(function (error) {
    console.log('ERROR:', error)
  })

Redis

Module: redis

Y├╝kleme

$ npm install redis

├ľrnek

var redis = require('redis')
var client = redis.createClient()

client.on('error', function (err) {
  console.log('Error ' + err)
})

client.set('string key', 'string val', redis.print)
client.hset('hash key', 'hashtest 1', 'some value', redis.print)
client.hset(['hash key', 'hashtest 2', 'some other value'], redis.print)

client.hkeys('hash key', function (err, replies) {
  console.log(replies.length + ' replies:')

  replies.forEach(function (reply, i) {
    console.log('    ' + i + ': ' + reply)
  })

  client.quit()
})

SQL Server

Module: tedious

Y├╝kleme

$ npm install tedious

├ľrnek

var Connection = require('tedious').Connection
var Request = require('tedious').Request

var config = {
  server: 'localhost',
  authentication: {
    type: 'default',
    options: {
      userName: 'your_username', // g├╝ncelle
      password: 'your_password' // g├╝ncelle
    }
  }
}

var connection = new Connection(config)

connection.on('connect', function (err) {
  if (err) {
    console.log(err)
  } else {
    executeStatement()
  }
})

function executeStatement () {
  request = new Request("select 123, 'hello world'", function (err, rowCount) {
    if (err) {
      console.log(err)
    } else {
      console.log(rowCount + ' rows')
    }
    connection.close()
  })

  request.on('row', function (columns) {
    columns.forEach(function (column) {
      if (column.value === null) {
        console.log('NULL')
      } else {
        console.log(column.value)
      }
    })
  })

  connection.execSql(request)
}

SQLite

Module: sqlite3

Y├╝kleme

$ npm install sqlite3

├ľrnek

var sqlite3 = require('sqlite3').verbose()
var db = new sqlite3.Database(':memory:')

db.serialize(function () {
  db.run('CREATE TABLE lorem (info TEXT)')
  var stmt = db.prepare('INSERT INTO lorem VALUES (?)')

  for (var i = 0; i < 10; i++) {
    stmt.run('Ipsum ' + i)
  }

  stmt.finalize()

  db.each('SELECT rowid AS id, info FROM lorem', function (err, row) {
    console.log(row.id + ': ' + row.info)
  })
})

db.close()

Elasticsearch

Module: elasticsearch

Y├╝kleme

$ npm install elasticsearch

├ľrnek

var elasticsearch = require('elasticsearch')
var client = elasticsearch.Client({
  host: 'localhost:9200'
})

client.search({
  index: 'books',
  type: 'book',
  body: {
    query: {
      multi_match: {
        query: 'express js',
        fields: ['title', 'description']
      }
    }
  }
}).then(function (response) {
  var hits = response.hits.hits
}, function (error) {
  console.trace(error.message)
})