nim_couchdbapi
所属分类:编程语言基础
开发工具:Nim
文件大小:0KB
下载次数:0
上传日期:2023-09-05 01:37:12
上 传 者:
sh-1993
说明: nim编程语言的CouchDb rest api驱动程序,
(CouchDb rest api driver for nim programming language,)
文件列表:
LICENSE.md (1499, 2023-09-04)
couchdbapi.nimble (210, 2023-09-04)
couchdbapi.nimble~ (210, 2023-09-04)
src/ (0, 2023-09-04)
src/couchdbapi.nim (62424, 2023-09-04)
### About
https://github.com/zendbit/nim.couchdbapi is connection driver (REST API) to Apache CouchDb. This helper implements all functionality except the deprecated and authentication api.
### Installation
```
nimble install couchdbapi
```
### Usage
- Create couchdb object, the jwtToken is optional, if you want to use secure connection set secure to true (default false)
```nim
import couchdbapi
proc Test() {.async.} =
let couchDb = newCouchDb(
username = "administrator",
password = "administrator",
host = "127.0.0.1",
port = 5984,
jwtToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbmlzdHJhdG9yIiwia2lkIjoiYWRtaW5pc3RyYXRvciIsInJvbGVzIjpbIl9hZG1pbiJdfQ.NWQiPIV_yO937Uzg9YHZvFxRR8_osvLaK-lrjhOhxnM")
## switch database
couchDb.switchDatabase("zendblock")
## create database zendblock
echo await couchDb.databasePut()
## switch database
couchDb.switchDatabase("zendblock-snapshot")
## create database zendblock-snapshot for snapshot/replication
echo await couchDb.databasePut()
## replicate database from zendblock to zendblock-snapshot
echo await couchDb.serverPostReplicate(%*{
"source": "zendblock",
"target": "zendblock-snapshot"
})
if isMainModule:
waitFor Test()
```
### Create new document with attachment
```nim
proc newDocumentWithAttachments*(jsonData: JsonNode, attachments: seq[DocumentAttachment]): Future[tuple[body: string, boundary: string, length: int]] {.async.}
##
## create new document with given attachment
## will automatic convert to multipart/related
## if the attachment not valid (fileContent) file path
## it will use that content as attachment filewill
##
```
### Create new CouchDb object
```nim
proc newCouchDb*(
username: string,
password: string,
host: string,
port: int,
jwtToken: string = "",
secure: bool = false): CouchDb
##
## create new couchdb instance
## jwt token is optional
## if jwt toke empty will use basic auth
##
## CouchDb object
## hold couchdb information
## for secure/https set secure to true
## if jwt token exist default auth will use it
## if jwt token empty will fallback into basic auth
##
```
### Switch default database for entire operation
```nim
proc switchDatabase*(self: CouchDb, database: string) =
##
## switch to default database name for operation
##
```
### Get server information
Accessing the root of a CouchDB instance returns meta information about the instance. The response is a JSON structure containing information about the server, including a welcome message and the version of the server.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--
```nim
proc serverGetInfo*(self: CouchDb): Future[JsonNode] {.async.} =
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--
##
```
### Get active tasks
List of running tasks, including the task type, name, status and process ID. The result is a JSON array of the currently running tasks, with each task being described with a single object. Depending on operation type set of response object fields might be different.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_active_tasks
```nim
proc serverGetActiveTasks*(self: CouchDb): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_active_tasks
##
```
### Get all databases in server
Returns a list of all the databases in the CouchDB instance.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_all_dbs
```nim
proc serverGetAllDbs*(self: CouchDb, descending: bool = false, startkey: JsonNode = nil, endkey: JsonNode = nil, skip: int = 0, limit: int = 0): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_all_dbs
##
```
### Get database info
Returns a list of all the databases information in the CouchDB instance.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_dbs_info
```nim
proc serverGetDbsInfo*(self: CouchDb, descending: bool = false, startkey: JsonNode = nil, endkey: JsonNode = nil, limit: int = 0, skip: int = 0): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_dbs_info
##
```
### Post to get database info
Returns information of a list of the specified databases in the CouchDB instance. This enables you to request information about multiple databases in a single request, in place of multiple GET /{db} requests.
- see https://docs.couchdb.org/en/latest/api/server/common.html#post--_dbs_info
```nim
proc serverPostDbsInfo*(self: CouchDb, keys: seq[JsonNode]): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#post--_dbs_info
##
```
### Get server cluster setup
Returns the status of the node or cluster, per the cluster setup wizard.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_cluster_setup
```nim
proc serverGetClusterSetup*(self: CouchDb, ensureDbsExist: seq[string] = @["_users", "_replicator"]): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_cluster_setup
##
```
### Post to configure cluster, setup as node cluster
Configure a node as a single (standalone) node, as part of a cluster, or finalise a cluster.
- see https://docs.couchdb.org/en/latest/api/server/common.html#post--_cluster_setup
```nim
proc serverPostClusterSetup*(self: CouchDb, jsonData: JsonNode): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#post--_cluster_setup
##
```
### Get database updates
Returns a list of all database events in the CouchDB instance. The existence of the _global_changes database is required to use this endpoint.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_db_updates
```nim
proc serverGetDbUpdates*(self: CouchDb, feed: string = "normal", timeout: int = 6000, heartbeat: int = 6000, since: string = "now"): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_db_updates
##
```
### Get nodes in cluster
Displays the nodes that are part of the cluster as cluster_nodes. The field all_nodes displays all nodes this node knows about, including the ones that are part of the cluster. The endpoint is useful when setting up a cluster.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_membership
```nim
proc serverGetMembership*(self: CouchDb): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_membership
##
```
### Replicate database between node or local server
Request, configure, or stop, a replication operation.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_membership
```nim
proc serverPostReplicate*(self: CouchDb, jsonData: JsonNode): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_membership
##
```
### Get scheduler jobs
List of replication jobs. Includes replications created via /_replicate endpoint as well as those created from replication documents. Does not include replications which have completed or have failed to start because replication documents were malformed. Each job description will include source and target information, replication id, a history of recent event, and a few other things.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_scheduler-jobs
```nim
proc serverGetSchedulerJobs*(self: CouchDb, limit: int, skip: int = 0): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_scheduler-jobs
##
```
### Get scheduler docs
List of replication document states. Includes information about all the documents, even in completed and failed states. For each document it returns the document ID, the database, the replication ID, source and target, and other information.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_scheduler-docs
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_scheduler-docs-replicator_db
```nim
proc serverGetSchedulerDocs*(self: CouchDb, limit: int, skip: int = 0, replicatorDb: string = ""): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_scheduler-docs
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_scheduler-docs-replicator_db
##
```
### Get scheduler docs
Get information about replication documents from a replicator database. The default replicator database is _replicator but other replicator databases can exist if their name ends with the suffix /_replicator.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_scheduler-docs-replicator_db-docid
```nim
proc serverGetSchedulerDocs*(self: CouchDb, replicatorDb: string, docId: string): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_scheduler-docs-replicator_db-docid
##
```
### Get node
The /_node/{node-name} endpoint can be used to confirm the Erlang node name of the server that processes the request. This is most useful when accessing /_node/_local to retrieve this information. Repeatedly retrieving this information for a CouchDB endpoint can be useful to determine if a CouchDB cluster is correctly proxied through a reverse load balancer.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_node-node-name
```nim
proc serverGetNode*(self: CouchDb, nodeName: string): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_node-node-name
##
```
### Get node state
The _stats resource returns a JSON object containing the statistics for the running server. The object is structured with top-level sections collating the statistics for a range of entries, with each individual statistic being easily identified, and the content of each statistic is self-describing.
Statistics are sampled internally on a configurable interval. When monitoring the _stats endpoint, you need to use a polling frequency of at least twice this to observe accurate results. For example, if the interval is 10 seconds, poll _stats at least every 5 seconds.
The literal string _local serves as an alias for the local node name, so for all stats URLs, {node-name} may be replaced with _local, to interact with the local node’s statistics.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_node-node-name-_stats
```nim
proc serverGetNodeStats*(self: CouchDb, nodeName: string): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_node-node-name-_stats
##
```
### Get node in prometheus format
The _prometheus resource returns a text/plain response that consolidates our /_node/{node-name}/_stats, and /_node/{node-name}/_system endpoints. The format is determined by Prometheus. The format version is 2.0.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_node-node-name-_prometheus
```nim
proc serverGetNodePrometheus*(self: CouchDb, nodeName: string): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_node-node-name-_prometheus
##
```
### Get node system
The _system resource returns a JSON object containing various system-level statistics for the running server. The object is structured with top-level sections collating the statistics for a range of entries, with each individual statistic being easily identified, and the content of each statistic is self-describing.
The literal string _local serves as an alias for the local node name, so for all stats URLs, {node-name} may be replaced with _local, to interact with the local node’s statistics.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_node-node-name-_system
```nim
proc serverGetNodeSystem*(self: CouchDb, nodeName: string): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_node-node-name-_system
##
```
### Post to restart node
This API is to facilitate integration testing only it is not meant to be used in production.
- see https://docs.couchdb.org/en/latest/api/server/common.html#post--_node-node-name-_restart
```nim
proc serverPostNodeRestart*(self: CouchDb, nodeName: string): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#post--_node-node-name-_restart
##
```
### Get node versions
The _versions resource returns a JSON object containing various system-level informations for the running server.
The literal string _local serves as an alias for the local node name, so for all stats URLs, {node-name} may be replaced with _local, to interact with the local node’s informations.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_node-node-name-_versions
```nim
proc serverGetNodeVersions*(self: CouchDb, nodeName: string): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_node-node-name-_versions
##
```
### Post test lucene analyzer
Tests the results of Lucene analyzer tokenization on sample text.
- see https://docs.couchdb.org/en/latest/api/server/common.html#post--_search_analyze
```nim
proc serverPostSearchAnalyze*(self: CouchDb, field: string, text: string): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#post--_search_analyze
##
```
### Get if server up
Confirms that the server is up, running, and ready to respond to requests. If maintenance_mode is true or nolb, the endpoint will return a 404 response.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_up
```nim
proc serverGetUp*(self: CouchDb): Future[JsonNode] {.async.} =
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_up
##
```
### Get uuids
Requests one or more Universally Unique Identifiers (UUIDs) from the CouchDB instance. The response is a JSON object providing a list of UUIDs.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_uuids
```nim
proc serverGetUUIDs*(self: CouchDb, count: int = 0): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_uuids
##
```
### Get count of completed resharding
Returns a count of completed, failed, running, stopped, and total jobs along with the state of resharding on the cluster.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_reshard
```nim
proc serverGetReshard*(self: CouchDb): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_reshard
##
```
### Get resharding state
Returns the resharding state and optional information about the state.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_reshard-state
```nim
proc serverGetReshardState*(self: CouchDb): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_reshard-state
##
```
### Put reshard state
Change the resharding state on the cluster. The states are stopped or running. This starts and stops global resharding on all the nodes of the cluster. If there are any running jobs, they will be stopped when the state changes to stopped. When the state changes back to running those job will continue running.
- see https://docs.couchdb.org/en/latest/api/server/common.html#put--_reshard-state
```nim
proc serverPutReshardState*(self: CouchDb, jsonData: JsonNode): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#put--_reshard-state
##
```
### Get reshard jobs
The shape of the response and the total_rows and offset field in particular are meant to be consistent with the _scheduler/jobs endpoint.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_reshard-jobs
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_reshard-jobs-jobid
```nim
proc serverGetReshardJobs*(self: CouchDb, jobId: string = ""): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_reshard-jobs
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_reshard-jobs-jobid
##
```
### Post reshard jobs
Depending on what fields are specified in the request, one or more resharding jobs will be created. The response is a json array of results. Each result object represents a single resharding job for a particular node and range. Some of the responses could be successful and some could fail. Successful results will have the "ok": true key and and value, and failed jobs will have the "error": "{error_message}" key and value.
- see https://docs.couchdb.org/en/latest/api/server/common.html#post--_reshard-jobs
```nim
proc serverPostReshardJobs*(self: CouchDb, jsonData: JsonNode): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#post--_reshard-jobs
##
```
### Delete reshard jobs
If the job is running, stop the job and then remove it.
- see https://docs.couchdb.org/en/latest/api/server/common.html#delete--_reshard-jobs-jobid
```nim
proc serverDeleteReshardJobs*(self: CouchDb, jobId: string): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#delete--_reshard-jobs-jobid
##
```
### Get reshard jobs state
Returns the running state of a resharding job identified by jobid.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_reshard-jobs-jobid-state
```nim
proc serverGetReshardJobsState*(self: CouchDb, jobId: string, state: string, reason: string): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_reshard-jobs-jobid-state
##
```
### Put reshard jobs state
Change the state of a particular resharding job identified by jobid. The state can be changed from stopped to running or from running to stopped. If an individual job is stopped via this API it will stay stopped even after the global resharding state is toggled from stopped to running. If the job is already completed its state will stay completed.
- see https://docs.couchdb.org/en/latest/api/server/common.html#get--_reshard-jobs-jobid-state
```nim
proc serverPutReshardJobsState*(self: CouchDb, jobId: string, jsonData: JsonNode): Future[JsonNode] {.async.}
##
## https://docs.couchdb.org/en/latest/api/server/common.html#get--_reshard-jobs-jobid-state
##
```
### Get node config
Returns the entire CouchDB server configuration as a JSON structure. The structure is organized by different configuration sections, with individual values.
- see https://docs.couchdb.org/en/latest/api/server/configuration.html#get--_node-node-name-_config
- see https://docs.couchdb.org/en/latest/api/server/configuration.html#get--_node-node-name-_config-section
- see https://docs.couchdb.org/en/latest/api/server/configuration.html#get--_node-node-name-_config-section-key
```nim
proc serverGetNodeConfig*(self: CouchDb, nodeName: string, section: string = "", key: string = ""): Future[JsonNode] {.async.}
##
## https://doc ... ...
近期下载者:
相关文件:
收藏者: