Coder Social home page Coder Social logo

gm_bson's Introduction

gm_bson

bson for gmod

Docs

Bson

bson.as_json

Alias: bson.as_relaxed_json
Attribute, computed on __index call.

Converts BSON to relaxed extJSON.

local bsn = bson.from_lua { a = 1 }
print(bsn.as_json) --> {"a":1}

bson.as_canonical_json

Attribute, computed on __index call.

Converts BSON to canonical extJSON.

local bsn = bson.from_lua { a = 1 }
print(bsn.as_canonical_json) --> {"$numberInt":1}

bson.__tostring(self)

Metamethod, computed on call.

Same as bson.as_json

print(bson.from_lua {a=1}} --> {"a":1}

bson.from_lua(value: any): Bson

Converts any lua type into Bson.
Unsupported types: function, lightuserdata, thread

local data = bson.from_lua {
  _id = bson.objectid(),
  name = "John",
  age = 31,
}

bson.to_lua(value: Bson): any

Converts Bson value into lua.

local table = bson.to_lua(data)
-- _id = objectid(smth),
-- name = "John",
-- age = 31,

bson.objectid(oid: string | nil): objectid

Creates new ObjectID from given Base64 value or generates a new one.

local oid = bson.objectid()
-- or
local oid = bson.objectid("stmth")

bson.datetime(ms: integer | nil): datetime

Creates new Datetime from given timestamp or from current time.

local dt = bson.datetime(1)
-- or
local dt = bson.datetime()

bson.timestamp(time: integer, increment: integer | nil): timestamp

Creates new Timestamp from given time and increment, if present.

local ts = bson.timestamp(1, 1)
-- or
local ts = bson.timestamp(1)

bson.binary(bin: string): binary

Creates new Generic Binary from given string.

local bin = bson.binary "123"

bson.regex(pattern: string, options: string | nil): regex

Creates new Regex from given pattern and options, if present.
Patterns must be in ECMAScript format.

local rx = bson.regex("\\w*", "i")
-- or 
local rx = bson.regex("\\d+")

bson.code(code: string): code

Creates new Code from given string.
Code must be written in JavaScript

local code = bson.code("console.log()")

bson.minkey(): minkey

Creates new MinKey

local mnk = bson.minkey()

bson.maxkey(): maxkey

Creates new MaxKey

local mxk = bson.maxkey()

bson.decimal128(dcml: string): decimal128

Creates new Decimal128 from given string.
String must be a valid number

local dcml = bson.decimal128 "123"

gm_bson's People

Contributors

kithf avatar

Watchers

 avatar

Forkers

kithf

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.