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 HEX: FF0000 mask
17 16 random-bits HEX: FFFF mask
20 TUPLE: dbref ref id db ;
22 CONSTRUCTOR: dbref ( ref id -- dbref ) ;
24 : dbref>assoc ( dbref -- assoc )
25 [ <linked-hash> ] dip over
27 [ [ ref>> "$ref" ] [ set-at ] bi* ]
28 [ [ id>> "$id" ] [ set-at ] bi* ]
30 [ db>> "$db" ] [ set-at ] bi*
34 : assoc>dbref ( assoc -- dbref )
35 [ "$ref" swap at ] [ "$id" swap at ] [ "$db" swap at ] tri
38 : dbref-assoc? ( assoc -- ? )
39 { [ "$ref" swap key? ] [ "$id" swap key? ] } 1&& ; inline
41 TUPLE: mdbregexp { regexp string } { options string } ;
43 : <mdbregexp> ( string -- mdbregexp )
44 [ mdbregexp new ] dip >>regexp ;
47 CONSTANT: MDB_OID_FIELD "_id"
48 CONSTANT: MDB_META_FIELD "_mfd"
52 CONSTANT: T_Integer 16
58 CONSTANT: T_Undefined 6
65 CONSTANT: T_ScopedCode 17
67 CONSTANT: T_JSTypeMax 16
68 CONSTANT: T_MaxKey 127
70 CONSTANT: T_Binary_Function 1
71 CONSTANT: T_Binary_Bytes 2
72 CONSTANT: T_Binary_UUID 3
73 CONSTANT: T_Binary_MD5 5
74 CONSTANT: T_Binary_Custom 128