XU XUv0.8.8
中文

API

#github.com/xulang-org/packages/mongodb

import: mongodb #github.com/xulang-org/packages/mongodb

counts: 21 fns, 16 methods, 2 types, 0 consts, 0 ifaces

MongoDB Document Database Native Driver for Xu Features Pure native MongoDB Wire Protocol (OP_MSG opcode 2012) implementation. Lightweight BSON encoding and decoding without external dependencies. Full session handshake (hello). Document CRUD: insert_one, find, drop_collection, run_command. Connection pooling via reusable TCP socket channels.

github.com/xulang-org/packages · 0.1.1 · Install and use

open

XuAPI
pub fn open(addr string) Client

Purpose

MongoDB Document Database Native Driver for Xu Features Pure native MongoDB Wire Protocol (OP_MSG opcode 2012) implementation. Lightweight BSON encoding and decoding without external dependencies. Full session handshake (hello). Document CRUD: insert_one, find, drop_collection, run_command. Connection pooling via reusable TCP socket channels. Throws on failure.

Parameters

addr string
address (string)

Returns

Client — a value of this type

open_pool

XuAPI
pub fn open_pool(addr string, max_idle int) Pool

Purpose

Open pool.

Parameters

addr string
address (string)
max_idle int
max_idle (int)

Returns

Pool — a value of this type

encode_i32

XuAPI
pub fn encode_i32(v int) string

Purpose

Lightweight BSON Encoder & Decoder for MongoDB Wire Protocol.

Parameters

v int
value (int)

Returns

string — result string

encode_i64

XuAPI
pub fn encode_i64(v int) string

Purpose

Encode.

Parameters

v int
value (int)

Returns

string — result string

decode_i32

XuAPI
pub fn decode_i32(s &string, off int) int

Purpose

Decode.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)
off int
offset (int)

Returns

int — a value of this type

build_doc

XuAPI
pub fn build_doc(elements string) string

Purpose

Build doc.

Parameters

elements string
elements (string)

Returns

string — result string

bson_string

XuAPI
pub fn bson_string(name string, val string) string

Purpose

Bson string.

Parameters

name string
name (string)
val string
value (string)

Returns

string — result string

bson_int32

XuAPI
pub fn bson_int32(name string, val int) string

Purpose

Bson int32.

Parameters

name string
name (string)
val int
value (int)

Returns

string — result string

bson_int64

XuAPI
pub fn bson_int64(name string, val int) string

Purpose

Bson int64.

Parameters

name string
name (string)
val int
value (int)

Returns

string — result string

bson_bool

XuAPI
pub fn bson_bool(name string, val bool) string

Purpose

Bson bool.

Parameters

name string
name (string)
val bool
value (bool)

Returns

string — result string

bson_doc

XuAPI
pub fn bson_doc(name string, doc_bytes string) string

Purpose

Bson doc.

Parameters

name string
name (string)
doc_bytes string
doc_bytes (string)

Returns

string — result string

bson_array

XuAPI
pub fn bson_array(name string, arr_bytes string) string

Purpose

Bson array.

Parameters

name string
name (string)
arr_bytes string
arr_bytes (string)

Returns

string — result string

bson_object_id

XuAPI
pub fn bson_object_id(name string, oid_bytes string) string

Purpose

Bson object id.

Parameters

name string
name (string)
oid_bytes string
oid_bytes (string)

Returns

string — result string

bson_utc_datetime

XuAPI
pub fn bson_utc_datetime(name string, millis int) string

Purpose

Bson utc datetime.

Parameters

name string
name (string)
millis int
millis (int)

Returns

string — result string

bson_null

XuAPI
pub fn bson_null(name string) string

Purpose

Bson null.

Parameters

name string
name (string)

Returns

string — result string

find_bson_string

XuAPI
pub fn find_bson_string(doc string, target_field string) string

Purpose

Find bson string.

Parameters

doc string
doc (string)
target_field string
target_field (string)

Returns

string — result string

is_bson_ok

XuAPI
pub fn is_bson_ok(doc string) bool

Purpose

Whether it is bson ok.

Parameters

doc string
doc (string)

Returns

bool — true or false

struct Client

XuAPI
pub struct Client {
    pub fd int
    pub addr string
    pub next_req_id int
}

Purpose

Public struct `Client`.

Parameters

fd int
file descriptor
addr string
address
next_req_id int
field (int)

(&mut Client) write_exact

XuAPI
pub fn (c &mut Client) write_exact(data string) int

Purpose

Method on `&mut Client`: write exact. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
data string
data (string)

Returns

int — a value of this type

(&mut Client) read_exact

XuAPI
pub fn (c &mut Client) read_exact(n int) string

Purpose

Method on `&mut Client`: read exact. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
n int
count, length, or limit (int)

Returns

string — result string

(&mut Client) run_command

XuAPI
pub fn (c &mut Client) run_command(db_name string, cmd_elements string) string

Purpose

Method on `&mut Client`: run command. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
db_name string
db_name (string)
cmd_elements string
cmd_elements (string)

Returns

string — result string

connect

XuAPI
pub fn connect(addr string) Client

Purpose

connect; returns Client. Throws on failure.

Parameters

addr string
address (string)

Returns

Client — a value of this type

(&mut Client) hello

XuAPI
pub fn (c &mut Client) hello() bool

Purpose

Call `hello` on `&mut Client`.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)

Returns

bool — true or false

(&mut Client) insert_one

XuAPI
pub fn (c &mut Client) insert_one(db_name string, col_name string, doc_bytes string) int

Purpose

Method on `&mut Client`: insert one. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
db_name string
db_name (string)
col_name string
col_name (string)
doc_bytes string
doc_bytes (string)

Returns

int — a value of this type

(&mut Client) find_first_string

XuAPI
pub fn (c &mut Client) find_first_string(db_name string, col_name string, target_field string) string

Purpose

Method on `&mut Client`: find first string. Throws on failure.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
db_name string
db_name (string)
col_name string
col_name (string)
target_field string
target_field (string)

Returns

string — result string

(&mut Client) drop_collection

XuAPI
pub fn (c &mut Client) drop_collection(db_name string, col_name string) bool

Purpose

Method on `&mut Client`: drop collection.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)
db_name string
db_name (string)
col_name string
col_name (string)

Returns

bool — true or false

(&mut Client) close

XuAPI
pub fn (c &mut Client) close()

Purpose

Method on `&mut Client`: close the resource.

Parameters

c &mut Client
receiver &mut Client (exclusive borrow)

struct Pool

XuAPI
pub struct Pool {
    pub addr string
    pub idle chan int
    pub max_idle int
}

Purpose

Connection Pool for MongoDB. Uses channel of socket file descriptors for lightweight and high-throughput pooling.

Parameters

addr string
address
idle chan int
field (channel; type chan int)
max_idle int
field (int)

new_pool

XuAPI
pub fn new_pool(addr string, max_idle int) Pool

Purpose

Construct pool.

Parameters

addr string
address (string)
max_idle int
max_idle (int)

Returns

Pool — a value of this type

(&Pool) get

XuAPI
pub fn (p &Pool) get() Client

Purpose

Call `get` on `&Pool`. Throws on failure.

Parameters

p &Pool
receiver &Pool (borrow)

Returns

Client — a value of this type

(&Pool) put_conn

XuAPI
pub fn (p &Pool) put_conn(fd int)

Purpose

Method on `&Pool`: put connection.

Parameters

p &Pool
receiver &Pool (borrow)
fd int
file descriptor (int)

(&Pool) put

XuAPI
pub fn (p &Pool) put(c Client)

Purpose

Call `put` on `&Pool`.

Parameters

p &Pool
receiver &Pool (borrow)
c Client
byte or character code (Client)

(&Pool) hello

XuAPI
pub fn (p &Pool) hello() bool

Purpose

Call `hello` on `&Pool`.

Parameters

p &Pool
receiver &Pool (borrow)

Returns

bool — true or false

(&Pool) insert_one

XuAPI
pub fn (p &Pool) insert_one(db_name string, col_name string, doc_bytes string) int

Purpose

Method on `&Pool`: insert one. Throws on failure.

Parameters

p &Pool
receiver &Pool (borrow)
db_name string
db_name (string)
col_name string
col_name (string)
doc_bytes string
doc_bytes (string)

Returns

int — a value of this type

(&Pool) find_first_string

XuAPI
pub fn (p &Pool) find_first_string(db_name string, col_name string, target_field string) string

Purpose

Method on `&Pool`: find first string. Throws on failure.

Parameters

p &Pool
receiver &Pool (borrow)
db_name string
db_name (string)
col_name string
col_name (string)
target_field string
target_field (string)

Returns

string — result string

(&Pool) drop_collection

XuAPI
pub fn (p &Pool) drop_collection(db_name string, col_name string) bool

Purpose

Method on `&Pool`: drop collection.

Parameters

p &Pool
receiver &Pool (borrow)
db_name string
db_name (string)
col_name string
col_name (string)

Returns

bool — true or false

(&Pool) close

XuAPI
pub fn (p &Pool) close()

Purpose

Method on `&Pool`: close the resource.

Parameters

p &Pool
receiver &Pool (borrow)

encode_op_msg

XuAPI
pub fn encode_op_msg(request_id int, doc_bytes string) string

Purpose

MongoDB OP_MSG (Opcode 2013) Wire Protocol Framer

Parameters

request_id int
request_id (int)
doc_bytes string
doc_bytes (string)

Returns

string — result string

decode_op_msg_doc

XuAPI
pub fn decode_op_msg_doc(raw string) string

Purpose

Decode. Throws on failure.

Parameters

raw string
raw (string)

Returns

string — result string