2010-01-12 14:40:57 -05:00
|
|
|
! Copyright (C) 2010 Sascha Matzke.
|
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
|
USING: accessors assocs calendar combinators
|
|
|
|
|
combinators.short-circuit constructors kernel linked-assocs
|
|
|
|
|
math math.bitwise random strings uuid ;
|
2009-01-03 06:48:11 -05:00
|
|
|
IN: bson.constants
|
|
|
|
|
|
2009-03-01 16:45:38 -05:00
|
|
|
: <objid> ( -- objid )
|
2009-04-04 10:13:56 -04:00
|
|
|
uuid1 ; inline
|
2009-03-01 16:45:38 -05:00
|
|
|
|
|
|
|
|
TUPLE: oid { a initial: 0 } { b initial: 0 } ;
|
2009-01-23 00:53:08 -05:00
|
|
|
|
2010-01-12 14:40:57 -05:00
|
|
|
: <oid> ( -- oid )
|
|
|
|
|
oid new
|
|
|
|
|
now timestamp>micros >>a
|
|
|
|
|
8 random-bits 16 shift HEX: FF0000 mask
|
|
|
|
|
16 random-bits HEX: FFFF mask
|
|
|
|
|
bitor >>b ;
|
|
|
|
|
|
|
|
|
|
TUPLE: dbref ref id db ;
|
|
|
|
|
|
|
|
|
|
CONSTRUCTOR: dbref ( ref id -- dbref ) ;
|
|
|
|
|
|
|
|
|
|
: dbref>assoc ( dbref -- assoc )
|
|
|
|
|
[ <linked-hash> ] dip over
|
|
|
|
|
{
|
|
|
|
|
[ [ ref>> "$ref" ] [ set-at ] bi* ]
|
|
|
|
|
[ [ id>> "$id" ] [ set-at ] bi* ]
|
|
|
|
|
[ over db>> [
|
|
|
|
|
[ db>> "$db" ] [ set-at ] bi*
|
|
|
|
|
] [ 2drop ] if ]
|
|
|
|
|
} 2cleave ; inline
|
|
|
|
|
|
|
|
|
|
: assoc>dbref ( assoc -- dbref )
|
|
|
|
|
[ "$ref" swap at ] [ "$id" swap at ] [ "$db" swap at ] tri
|
|
|
|
|
dbref boa ; inline
|
2009-01-23 00:53:08 -05:00
|
|
|
|
2010-01-12 14:40:57 -05:00
|
|
|
: dbref-assoc? ( assoc -- ? )
|
|
|
|
|
{ [ "$ref" swap key? ] [ "$id" swap key? ] } 1&& ; inline
|
2009-04-04 05:10:13 -04:00
|
|
|
|
2009-03-17 12:50:46 -04:00
|
|
|
TUPLE: mdbregexp { regexp string } { options string } ;
|
|
|
|
|
|
|
|
|
|
: <mdbregexp> ( string -- mdbregexp )
|
|
|
|
|
[ mdbregexp new ] dip >>regexp ;
|
|
|
|
|
|
|
|
|
|
|
2009-03-02 12:44:24 -05:00
|
|
|
CONSTANT: MDB_OID_FIELD "_id"
|
2009-04-04 05:10:13 -04:00
|
|
|
CONSTANT: MDB_META_FIELD "_mfd"
|
2009-03-02 12:44:24 -05:00
|
|
|
|
2009-01-23 00:53:08 -05:00
|
|
|
CONSTANT: T_EOO 0
|
|
|
|
|
CONSTANT: T_Double 1
|
|
|
|
|
CONSTANT: T_Integer 16
|
|
|
|
|
CONSTANT: T_Boolean 8
|
|
|
|
|
CONSTANT: T_String 2
|
|
|
|
|
CONSTANT: T_Object 3
|
|
|
|
|
CONSTANT: T_Array 4
|
|
|
|
|
CONSTANT: T_Binary 5
|
|
|
|
|
CONSTANT: T_Undefined 6
|
|
|
|
|
CONSTANT: T_OID 7
|
|
|
|
|
CONSTANT: T_Date 9
|
|
|
|
|
CONSTANT: T_NULL 10
|
|
|
|
|
CONSTANT: T_Regexp 11
|
|
|
|
|
CONSTANT: T_DBRef 12
|
|
|
|
|
CONSTANT: T_Code 13
|
|
|
|
|
CONSTANT: T_ScopedCode 17
|
|
|
|
|
CONSTANT: T_Symbol 14
|
|
|
|
|
CONSTANT: T_JSTypeMax 16
|
|
|
|
|
CONSTANT: T_MaxKey 127
|
|
|
|
|
|
|
|
|
|
CONSTANT: T_Binary_Function 1
|
2009-02-01 11:40:52 -05:00
|
|
|
CONSTANT: T_Binary_Bytes 2
|
|
|
|
|
CONSTANT: T_Binary_UUID 3
|
|
|
|
|
CONSTANT: T_Binary_MD5 5
|
|
|
|
|
CONSTANT: T_Binary_Custom 128
|
2008-12-16 08:17:00 -05:00
|
|
|
|
|
|
|
|
|