Skip to content

Commit

Permalink
Merge pull request #24 from esquerbatua/main
Browse files Browse the repository at this point in the history
Make it work again
  • Loading branch information
JalonSolov authored Jan 1, 2024
2 parents 1701b9a + 22f8017 commit 10f1a27
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 23 deletions.
File renamed without changes.
8 changes: 7 additions & 1 deletion src/Makefile → Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.DEFAULT_GOAL := install
build:
build_mongo_c_driver:
apt install cmake libssl-dev libsasl2-dev
wget -O mongo-c-driver.tar.gz https://github.com/mongodb/mongo-c-driver/releases/download/1.16.2/mongo-c-driver-1.16.2.tar.gz # Check for the latest version
tar xzf mongo-c-driver.tar.gz
Expand All @@ -10,3 +10,9 @@ build:
make install
install:
apt install libbson-1.0-0 libmongoc-1.0-0

dev:
v -cg -shared watch .

build:
v -shared .
Binary file added mongo.so
Binary file not shown.
6 changes: 3 additions & 3 deletions src/bson.c_fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn C.bson_copy_to(&C.bson_t, &C.bson_t)
fn C.bson_copy_to_excluding(&C.bson_t, &C.bson_t, byteptr)
fn C.bson_count_keys(&C.bson_t) u32
fn C.bson_equal(&C.bson_t, &C.bson_t) bool
fn C.bson_get_data(&C.bson_t) byte
fn C.bson_get_data(&C.bson_t) u8
fn C.bson_has_field(&C.bson_t, byteptr) bool
fn C.bson_free(voidptr)
fn C.bson_as_canonical_extended_json(&C.bson_t, int) byteptr
Expand All @@ -30,7 +30,7 @@ fn C.bson_append_array_begin(&C.bson_t, byteptr, int, &C.bson_t) bool
fn C.bson_append_array_end(&C.bson_t, &C.bson_t) bool

// http://mongoc.org/libbson/current/bson_append_binary.html
fn C.bson_append_binary(&C.bson_t, byteptr, int, &C.bson_subtype_t, &byte, u32) bool
fn C.bson_append_binary(&C.bson_t, byteptr, int, &C.bson_subtype_t, &u8, u32) bool

// http://mongoc.org/libbson/current/bson_append_bool.html
fn C.bson_append_bool(&C.bson_t, byteptr, int, bool) bool
Expand Down Expand Up @@ -110,7 +110,7 @@ fn C.bson_oid_copy(&C.bson_oid_t, &C.bson_oid_t)
fn C.bson_oid_equal(&C.bson_oid_t, &C.bson_oid_t) bool
fn C.bson_oid_get_time_t(&C.bson_oid_t) int
fn C.bson_oid_hash(&C.bson_oid_t) u32
fn C.bson_oid_init_from_data(&C.bson_oid_t, byte)
fn C.bson_oid_init_from_data(&C.bson_oid_t, u8)
fn C.bson_oid_init_from_string(&C.bson_oid_t, byteptr)
fn C.bson_iter_find_descendant(&&C.bson_iter_t, &&char, &&bson_iter_t)

Expand Down
8 changes: 4 additions & 4 deletions src/bson.c_structs.v
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module mongo

// http://mongoc.org/libbson/current/bson_t.html
[typedef]
@[typedef]
pub struct C.bson_t {
flags u32 // Internal flags for the bson_t.
len u32 // Length of BSON data.
padding &u8 // Padding for stack allocation.
padding u8 // Padding for stack allocation.
}

// http://mongoc.org/libbson/current/bson_oid_t.html
[typedef]
@[typedef]
pub struct C.bson_oid_t {
bytes u8 // ObjectId is a 12-byte BSON type
}
Expand All @@ -33,7 +33,7 @@ pub struct C.bson_iter_t {}
pub struct C.bson_value_t {}

// http://mongoc.org/libbson/current/bson_error_t.html
[typedef]
@[typedef]
pub struct C.bson_error_t {
domain u32
code u32
Expand Down
8 changes: 4 additions & 4 deletions src/bson.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ pub fn new_bson() &C.bson_t {
return C.bson_new()
}

[inline]
@[inline]
pub fn new_bson_oid_filter(_oid string) &C.bson_t {
return new_from_json('{"_id": {"\$oid": "$_oid"}}')
}

[inline]
@[inline]
pub fn new_bson_from<T>(t T) &C.bson_t {
json_data := json.encode(t)
error := C.bson_error_t{}
Expand All @@ -23,7 +23,7 @@ pub fn new_bson_from<T>(t T) &C.bson_t {
return bson
}

[inline]
@[inline]
pub fn new_from_json(json_data string) &C.bson_t {
error := C.bson_error_t{}
bson := C.bson_new_from_json(json_data.str, json_data.len, &error)
Expand Down Expand Up @@ -97,7 +97,7 @@ pub fn (document &C.bson_t) count_keys() int {
return int(C.bson_count_keys(document))
}

pub fn (document &C.bson_t) get_data() byte {
pub fn (document &C.bson_t) get_data() u8 {
return C.bson_get_data(document)
}

Expand Down
2 changes: 1 addition & 1 deletion src/bson_oid.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn (oid &C.bson_oid_t) init() {
C.bson_oid_init(oid, 0)
}

pub fn (oid &C.bson_oid_t) init_from_data(data byte) {
pub fn (oid &C.bson_oid_t) init_from_data(data u8) {
C.bson_oid_init_from_data(oid, data)
}

Expand Down
3 changes: 3 additions & 0 deletions src/c_structs.v
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ pub struct C.mongoc_stream_t {}

// http://mongoc.org/libmongoc/current/mongoc_stream_file_t.html
pub struct C.mongoc_stream_file_t {}

// https://mongoc.org/libmongoc/current/mongoc_bulk_operation_t.html
pub struct C.mongoc_bulk_operation_t {}
4 changes: 2 additions & 2 deletions src/cursor.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module mongo
import json
import x.json2

[inline]
@[inline]
pub fn (cursor &C.mongoc_cursor_t) next_doc(document &&C.bson_t) bool {
return C.mongoc_cursor_next(cursor, document)
}
Expand Down Expand Up @@ -59,7 +59,7 @@ pub fn (cursor &C.mongoc_cursor_t) skip(skip int) &C.mongoc_cursor_t {
return unsafe { cursor }
}

document := &C.bson_t{}
document := C.bson_t{}

mut count := skip
for C.mongoc_cursor_next(cursor, &document) {
Expand Down
14 changes: 7 additions & 7 deletions src/database.v
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
module mongo

[inline]
@[inline]
pub fn (database &C.mongoc_database_t) write_command_with_opts(command &C.bson_t, opts &C.bson_t, result &C.bson_t) bool {
return C.mongoc_database_write_command_with_opts(database, command, opts, result,
0)
}

[inline]
@[inline]
pub fn (database &C.mongoc_database_t) create_collection(collection string) &C.mongoc_collection_t {
return C.mongoc_database_create_collection(database, collection.str, 0, 0)
}

[inline]
@[inline]
pub fn (database &C.mongoc_database_t) get_collections() &C.mongoc_cursor_t {
return C.mongoc_database_find_collections_with_opts(database, 0)
}

[inline]
@[inline]
pub fn (database &C.mongoc_database_t) add_user(user string, pass string, roles &C.bson_t) bool {
return C.mongoc_database_add_user(database, user.str, pass.str, 0, 0, 0)
}

[inline]
@[inline]
pub fn (database &C.mongoc_database_t) add_user_opts(user string, pass string, roles &C.bson_t, custom_data &C.bson_t) bool {
return C.mongoc_database_add_user(database, user.str, pass.str, roles, custom_data,
0)
}

[inline]
@[inline]
pub fn (database &C.mongoc_database_t) drop() bool {
return C.mongoc_database_drop(database, 0)
}

[inline]
@[inline]
pub fn (database &C.mongoc_database_t) destroy() {
C.mongoc_database_destroy(database)
}
2 changes: 1 addition & 1 deletion src/stream.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module mongo

import os

[inline]
@[inline]
pub fn new_stream_file(file os.File) &C.mongoc_stream_file_t {
return C.mongoc_stream_file_new(file.fd)
}
Expand Down
Empty file added v
Empty file.

0 comments on commit 10f1a27

Please sign in to comment.