1 ! Copyright (C) 2010 Sascha Matzke.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs calendar combinators
4 combinators.short-circuit constructors kernel linked-assocs
5 math math.bitwise random strings uuid ;
11 TUPLE: oid { a initial: 0 } { b initial: 0 } ;
15 now timestamp>micros >>a
16 8 random-bits 16 shift 0xFF0000 mask
17 16 random-bits 0xFFFF mask
20 TUPLE: dbref ref id db ;
22 TUPLE: mongo-timestamp incr seconds ;
24 : <mongo-timestamp> ( incr seconds -- mongo-timestamp )
27 TUPLE: mongo-scoped-code code object ;
29 : <mongo-scoped-code> ( code object -- mongo-scoped-code )
30 mongo-scoped-code boa ;
32 CONSTRUCTOR: dbref ( ref id -- dbref ) ;
34 : dbref>assoc ( dbref -- assoc )
35 [ <linked-hash> ] dip over
37 [ [ ref>> "$ref" ] [ set-at ] bi* ]
38 [ [ id>> "$id" ] [ set-at ] bi* ]
40 [ db>> "$db" ] [ set-at ] bi*
44 : assoc>dbref ( assoc -- dbref )
45 [ "$ref" of ] [ "$id" of ] [ "$db" of ] tri
48 : dbref-assoc? ( assoc -- ? )
49 { [ "$ref" swap key? ] [ "$id" swap key? ] } 1&& ; inline
51 TUPLE: mdbregexp { regexp string } { options string } ;
53 : <mdbregexp> ( string -- mdbregexp )
54 [ mdbregexp new ] dip >>regexp ;
57 CONSTANT: MDB_OID_FIELD "_id"
58 CONSTANT: MDB_META_FIELD "_mfd"
61 CONSTANT: T_Double 0x1
62 CONSTANT: T_String 0x2
63 CONSTANT: T_Object 0x3
65 CONSTANT: T_Binary 0x5
66 CONSTANT: T_Undefined 0x6
68 CONSTANT: T_Boolean 0x8
71 CONSTANT: T_Regexp 0xB
74 CONSTANT: T_Symbol 0xE
75 CONSTANT: T_ScopedCode 0xF
76 CONSTANT: T_Integer 0x10
77 CONSTANT: T_Timestamp 0x11
78 CONSTANT: T_Integer64 0x12
79 CONSTANT: T_MinKey 0xFF
80 CONSTANT: T_MaxKey 0x7F
82 CONSTANT: T_Binary_Default 0x0
83 CONSTANT: T_Binary_Function 0x1
84 CONSTANT: T_Binary_Bytes_Deprecated 0x2
85 CONSTANT: T_Binary_UUID 0x3
86 CONSTANT: T_Binary_MD5 0x5
87 CONSTANT: T_Binary_Custom 0x80