You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by gl...@apache.org on 2024/11/07 10:32:21 UTC
(couchdb-nano) 04/05: remove the examples as they are ancient and beyond redemption
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch remove-callbacks
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 72bcb2f09a4d5541e314f5a7a323bbbcecefccaf
Author: Glynn Bird <gl...@apache.org>
AuthorDate: Thu Nov 7 10:18:57 2024 +0000
remove the examples as they are ancient and beyond redemption
---
examples/bulk_transform.js | 46 -----------
examples/express.js | 29 -------
examples/lazy_creation_of_views.js | 115 ---------------------------
examples/lazy_db_creation_and_replication.js | 65 ---------------
examples/pipe.js | 25 ------
examples/readme.md | 7 --
6 files changed, 287 deletions(-)
diff --git a/examples/bulk_transform.js b/examples/bulk_transform.js
deleted file mode 100644
index 8954f71..0000000
--- a/examples/bulk_transform.js
+++ /dev/null
@@ -1,46 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-const db = require('nano')('http://127.0.0.1:5984/emails')
-const async = require('async')
-
-function updateRow (row, cb) {
- const doc = row.doc
- delete doc.subject
- db.insert(doc, doc._id, function (err, data) {
- if (err) { console.log('err at ' + doc._id); cb(err) } else { console.log('updated ' + doc._id); cb() }
- })
-}
-
-function list (offset) {
- let ended = false
- offset = offset || 0
- db.list({ include_docs: true, limit: 10, skip: offset },
- function (err, data) {
- let rows
- if (err) { console.log('fuuuu: ' + err.message); rows = []; return }
- const total = data.total_rows
- const offset = data.offset
- rows = data.rows
- if (offset === total) {
- ended = true
- return
- }
- async.forEach(rows, updateRow, function (err) {
- if (err) { console.log('something failed, check logs') }
- if (ended) { return }
- list(offset + 10)
- })
- })
-}
-
-list()
diff --git a/examples/express.js b/examples/express.js
deleted file mode 100644
index f09a725..0000000
--- a/examples/express.js
+++ /dev/null
@@ -1,29 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-const express = require('express')
-const db = require('nano')('http://127.0.0.1:5984/my_couch')
-const app = module.exports = express()
-
-app.get('/', function (req, res) {
- db.get('foo', function (error, body, headers) {
- if (error) {
- res.status(error.statusCode)
- return res.send(error.message)
- }
- res.status(200)
- res.send(body)
- })
-})
-
-app.listen(3333)
-console.log('server is running. check expressjs.com for more cool tricks')
diff --git a/examples/lazy_creation_of_views.js b/examples/lazy_creation_of_views.js
deleted file mode 100644
index 47b8524..0000000
--- a/examples/lazy_creation_of_views.js
+++ /dev/null
@@ -1,115 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-module.exports = function () {
- const nano = require('nano')('http://127.0.0.1:5984')
- const users = nano.use('users')
- const VIEWS = {
- by_twitter_id:
- { map: 'function(doc) { emit(doc.twitter.screen_name, doc); }' }
- }
-
- /*****************************************************************************
- * user.get()
- ****************************************************************************/
- function userGet (id, callback) {
- return users.get(id, callback)
- }
-
- /*****************************************************************************
- * user.new()
- ****************************************************************************/
- function userNew (id, body, callback) {
- return users.insert(body, id, callback)
- }
-
- /*****************************************************************************
- * user.create()
- ****************************************************************************/
- function createUsersDatabase (emailAddress, secret, name, retries) {
- nano.db.create('users', function (e, b, h) {
- userCreate(emailAddress, secret, name, retries + 1)
- })
- }
-
- function userCreate (emailAddress, secret, name, retries) {
- if (!retries) {
- retries = 0
- }
- users.insert({ emailAddress, secret, name }, secret,
- function (e, b, h) {
- if (e && e.message === 'no_db_file' && retries < 1) {
- return createUsersDatabase(emailAddress, secret, name, retries)
- }
- (function () { })(e, b, h)
- })
- }
-
- /*****************************************************************************
- * user.find()
- ****************************************************************************/
- //
- // some more logic needed
- // what if design document exists but view doesnt, we cant just overwrite it
- //
- // we need a way to fectch and build on
- // and thats the reason why im not doing this at 5am
-
- function userFind (view, id, opts, tried, callback) {
- if (typeof tried === 'function') {
- callback = tried
- tried = { tried: 0, max_retries: 2 }
- }
- users.view('users', view, opts, function (e, b, h) {
- if (e) {
- const currentView = VIEWS[view]
- if (!currentView) {
- e.message = 'View is not available'
- return callback(e, b, h)
- }
- if (tried.tried < tried.max_retries) {
- if (e.message === 'missing' || e.message === 'deleted') { // create design document
- const designDoc = { views: {} }
- designDoc.views[view] = currentView
- return users.insert(designDoc, '_design/users', function () {
- tried.tried += 1
- userFind(view, id, opts, tried, callback)
- })
- }
- if (e.message === 'missing_named_view') {
- users.get('_design/users', function (e, b, h) { // create view
- tried.tried += 1
- if (e) { return userFind(view, id, opts, tried, callback) }
- b.views[view] = currentView
- users.insert(b, '_design/users', function (e, b, h) {
- return userFind(view, id, opts, tried, callback)
- })
- })
- return
- }
- } else { return callback(e, b, h) }
- }
- return callback(null, b, h)
- })
- }
-
- function userFirst (view, id, callback) {
- return userFind(view, id, { startkey: ('"' + id + '"'), limit: 1 }, callback)
- }
-
- return {
- new: userNew,
- get: userGet,
- create: userCreate,
- first: userFirst
- }
-}
diff --git a/examples/lazy_db_creation_and_replication.js b/examples/lazy_db_creation_and_replication.js
deleted file mode 100644
index ae10c5d..0000000
--- a/examples/lazy_db_creation_and_replication.js
+++ /dev/null
@@ -1,65 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-const nano = require('nano')
-const couch =
- {
- master: 'http://127.0.0.1:5984/landing_m',
- replica: 'http://127.0.0.1:5984/landing_r'
- }
-
-function insertWithRetry (db, email, retries, callback) {
- if (typeof retries === 'function') {
- callback = retries
- retries = 0
- }
- callback = callback || function () {}
- db.insert(email, function (err, resp, head) {
- if (err) {
- if (err.message === 'no_db_file' && retries < 1) {
- const dbName = db.config.db
- const server = nano(db.config.url)
-
- server.db.create(dbName, function (err2, resp2, head2) {
- if (err2) { return callback(err2, resp2, head2) }
- insertWithRetry(db, email, retries + 1, callback)
- })
- } else { return callback(err, resp, head) }
- }
- callback(err, resp, head)
- })
-}
-
-function replicateWithRetry (masterUri, replicaUri, retries, callback) {
- if (typeof retries === 'function') {
- callback = retries
- retries = 0
- }
- callback = callback || function () {}
- retries = retries || 0
- const master = nano(couch.master)
- master.replicate(couch.replica, function (err, resp, head) {
- if (err && err.error === 'db_not_found' && retries < 1) {
- const replica = nano(couch.replica)
- const dbName = replica.config.db
- const server = nano(replica.config.url)
-
- server.db.create(dbName, function (err2, resp2, head2) {
- if (err2) { return callback(err2, resp2, head2) }
- replicateWithRetry(masterUri, replicaUri, retries + 1, callback)
- })
- }
- callback(err, resp, head)
- })
-}
-
-module.exports = { insert: insertWithRetry, replicate: replicateWithRetry }
diff --git a/examples/pipe.js b/examples/pipe.js
deleted file mode 100644
index 5f2cc9d..0000000
--- a/examples/pipe.js
+++ /dev/null
@@ -1,25 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-const express = require('express')
-const nano = require('nano')('http://127.0.0.1:5984')
-const app = express.createServer()
-const dbName = 'test'
-const db = nano.use(dbName)
-
-app.get('/', function (request, response) {
- db.attachment.get('new', 'logo.png').pipe(response)
-})
-
-app.listen(3333)
-
-module.exports = app
diff --git a/examples/readme.md b/examples/readme.md
deleted file mode 100644
index 093b7cd..0000000
--- a/examples/readme.md
+++ /dev/null
@@ -1,7 +0,0 @@
-# samples
-
-if you have a sample please feel free to send a pull request.
-
-also the tests are very concise and helpful.
-
-i would recommend taking a peek.
\ No newline at end of file