clients.couchdb #
CouchDB Client
Once installed documentation can be see on http://127.0.0.1:5984/_utils/docs/intro/api.html
fn get #
fn get(instance string, cfg Config) !CouchDBClient[Config]
fn (CouchDBClient[Config]) db_instance #
fn (mut cl CouchDBClient[Config]) db_instance(db_name string) !CouchDBInstance
return DB client
fn (CouchDBClient[Config]) db_create #
fn (mut cl CouchDBClient[Config]) db_create(args CoudDBCreateArgs) !
fn (CouchDBClient[Config]) db_delete #
fn (mut cl CouchDBClient[Config]) db_delete(name string) !
fn (CouchDBClient[Config]) db_list #
fn (mut cl CouchDBClient[Config]) db_list() ![]string
list dbs found on connection
struct Attachment #
struct Attachment {
pub mut:
content_type string
data ?string
digest string
encoded_length ?u64
encoding ?string
length ?u64
revpos u64
stub ?bool
}
QUESTION: how should we deal with big documents
struct Cluster #
struct Cluster {
pub mut:
n u64
q u64
r u64
w u64
}
struct Config #
@[params]
struct Config {
pub mut:
url string
username string
password string @[secret]
}
struct CouchDBClient #
struct CouchDBClient[T] {
base.BaseConfig[T]
pub mut:
connection &httpconnection.HTTPConnection
username string
}
import freeflowuniverse.crystallib.ui.console
struct CouchDBInstance #
struct CouchDBInstance {
pub mut:
// db name
name string
connection &httpconnection.HTTPConnection
}
one specific DB in the CouchDB server
fn (CouchDBInstance) attachment_add #
fn (mut cl CouchDBInstance) attachment_add(doc_id ID, rev Rev, attachment_name string, data string) !(ID, Rev)
fn (CouchDBInstance) attachment_delete #
fn (mut cl CouchDBInstance) attachment_delete(doc_id ID, rev Rev, attachment_name string) !(ID, Rev)
fn (CouchDBInstance) attachment_get #
fn (mut cl CouchDBInstance) attachment_get(doc_id string, attachment_name string) !string
fn (CouchDBInstance) attachment_list #
fn (mut cl CouchDBInstance) attachment_list(doc_id ID) !Attachments
fn (CouchDBInstance) create_document #
fn (mut cl CouchDBInstance) create_document[T](doc T) !(ID, Rev)
fn (CouchDBInstance) create_or_update_document #
fn (mut cl CouchDBInstance) create_or_update_document[T](doc_id ID, rev ?Rev, doc T) !(ID, Rev)
fn (CouchDBInstance) delete_document #
fn (mut cl CouchDBInstance) delete_document(doc_id ID, rev Rev) !
fn (CouchDBInstance) get_db #
fn (mut cl CouchDBInstance) get_db() !DB
fn (CouchDBInstance) get_document #
fn (mut cl CouchDBInstance) get_document[T](doc_id ID, params GetDocumentQueryParams) !(T, DocInfo)
fn (CouchDBInstance) replication_add #
fn (mut cl CouchDBInstance) replication_add() !
fn (CouchDBInstance) replication_delete #
fn (mut cl CouchDBInstance) replication_delete() !
fn (CouchDBInstance) replication_get #
fn (mut cl CouchDBInstance) replication_get() !
see http://127.0.0.1:5984/_utils/docs/intro/api.html#replication
fn (CouchDBInstance) replication_list #
fn (mut cl CouchDBInstance) replication_list() !
struct CoudDBCreateArgs #
@[params]
struct CoudDBCreateArgs {
pub mut:
// database name
name string
// they have all the privileges of members plus the privileges: write (and edit) design documents,
// add/remove database admins and members and set the database revisions limit.
// They can not create a database nor delete a database.
admins []string
// they can read all types of documents from the DB, and they can write (and edit) documents to the DB except for design documents.
members []string
}
struct DB #
struct DB {
pub mut:
instance_start_time u64
db_name string
purge_seq string
update_seq string
sizes Sizes
props Props
doc_del_count u64
doc_count u64
disk_format_version u64
compact_running bool
cluster Cluster
}
struct DBSecurity #
@[params]
struct DBSecurity {
pub mut:
admins DBUsers
members DBUsers
}
struct DBUsers #
@[params]
struct DBUsers {
pub mut:
names []string
roles []string
}
struct DocInfo #
struct DocInfo {
id string @[json: '_id']
rev string @[json: '_rev']
deleted ?bool @[json: '_deleted']
attachments ?Attachments @[json: '_attachments']
conflicts ?[]string @[json: '_conflicts']
deleted_conflicts ?[]string @[json: '_deleted_conflicts']
local_seq ?string @[json: '_local_seq']
revs_info ?[]RevInfo @[json: '_revs_info']
revisions ?[]string @[json: '_revisions']
}
struct GetDocumentQueryParams #
@[params]
struct GetDocumentQueryParams {
pub mut:
// Includes attachments bodies in response.
attachments ?bool
// Includes encoding information in attachment stubs if the particular attachment is compressed.
att_encoding_info ?bool
// Includes attachments only since specified revisions. Doesn’t includes attachments for specified revisions.
atts_since ?[]string
// Includes information about conflicts in document.
conflicts ?bool
// Includes information about deleted conflicted revisions.
deleted_conflicts ?bool
// Forces retrieving latest “leaf” revision, no matter what rev was requested.
latest ?bool
// Includes last update sequence for the document.
local_seq ?bool
// Acts same as specifying all conflicts, deleted_conflicts and revs_info query parameters.
meta ?bool
// Retrieves documents of specified leaf revisions. Additionally, it accepts value as all to return all leaf revisions.
open_revs ?[]string
// Retrieves document of specified revision.
rev ?string
// Includes list of all known document revisions.
revs ?bool
// Includes detailed information for all known document revisions.
revs_info ?bool
}
struct Props #
struct Props {
pub mut:
partitioned bool
}
struct RevInfo #
struct RevInfo {
pub mut:
rev string
status string
}
struct Sizes #
struct Sizes {
pub mut:
file u64
external u64
active u64
}