summaryrefslogtreecommitdiffstats
path: root/src/rocksdb/tools/rdb/API.md
blob: e9c2e5925c51d6836532a101e350b7346cab308c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# JavaScript API

## DBWrapper

### Constructor

    # Creates a new database wrapper object
    RDB()

### Open

    # Open a new or existing RocksDB database.
    #
    # db_name         (string)   - Location of the database (inside the
    #                              `/tmp` directory).
    # column_families (string[]) - Names of additional column families
    #                              beyond the default. If there are no other
    #                              column families, this argument can be
    #                              left off.
    #
    # Returns true if the database was opened successfully, or false otherwise
    db_obj.(db_name, column_families = [])

### Get

    # Get the value of a given key.
    #
    # key           (string) - Which key to get the value of.
    # column_family (string) - Which column family to check for the key.
    #                          This argument can be left off for the default
    #                          column family
    #
    # Returns the value (string) that is associated with the given key if
    # one exists, or null otherwise.
    db_obj.get(key, column_family = { default })

### Put

    # Associate a value with a key.
    #
    # key           (string) - Which key to associate the value with.
    # value         (string) - The value to associate with the key.
    # column_family (string) - Which column family to put the key-value pair
    #                          in. This argument can be left off for the
    #                          default column family.
    #
    # Returns true if the key-value pair was successfully stored in the
    # database, or false otherwise.
    db_obj.put(key, value, column_family = { default })

### Delete

    # Delete a value associated with a given key.
    #
    # key           (string) - Which key to delete the value of..
    # column_family (string) - Which column family to check for the key.
    #                          This argument can be left off for the default
    #                          column family
    #
    # Returns true if an error occurred while trying to delete the key in
    # the database, or false otherwise. Note that this is NOT the same as
    # whether a value was deleted; in the case of a specified key not having
    # a value, this will still return true. Use the `get` method prior to
    # this method to check if a value existed before the call to `delete`.
    db_obj.delete(key, column_family = { default })

### Dump

    # Print out all the key-value pairs in a given column family of the
    # database.
    #
    # column_family (string) - Which column family to dump the pairs from.
    #                          This argument can be left off for the default
    #                          column family.
    #
    # Returns true if the keys were successfully read from the database, or
    # false otherwise.
    db_obj.dump(column_family = { default })

### WriteBatch

    # Execute an atomic batch of writes (i.e. puts and deletes) to the
    # database.
    #
    # cf_batches (BatchObject[]; see below) - Put and Delete writes grouped
    #                                         by column family to execute
    #                                         atomically.
    #
    # Returns true if the argument array was well-formed and was
    # successfully written to the database, or false otherwise.
    db_obj.writeBatch(cf_batches)

### CreateColumnFamily

    # Create a new column family for the database.
    #
    # column_family_name (string) - Name of the new column family.
    #
    # Returns true if the new column family was successfully created, or
    # false otherwise.
    db_obj.createColumnFamily(column_family_name)

### CompactRange

    # Compact the underlying storage for a given range.
    #
    # In addition to the endpoints of the range, the method is overloaded to
    # accept a non-default column family, a set of options, or both.
    #
    # begin (string)         - First key in the range to compact.
    # end   (string)         - Last key in the range to compact.
    # options (object)       - Contains a subset of the following key-value
    #                          pairs:
    #                            * 'target_level'   => int
    #                            * 'target_path_id' => int
    # column_family (string) - Which column family to compact the range in.
    db_obj.compactRange(begin, end)
    db_obj.compactRange(begin, end, options)
    db_obj.compactRange(begin, end, column_family)
    db_obj.compactRange(begin, end, options, column_family)



### Close

    # Close an a database and free the memory associated with it.
    #
    # Return null.
    # db_obj.close()


## BatchObject

### Structure

A BatchObject must have at least one of the following key-value pairs:

* 'put' => Array of ['string1', 'string1'] pairs, each of which signifies that
the key 'string1' should be associated with the value 'string2'
* 'delete' => Array of strings, each of which is a key whose value should be
deleted.

The following key-value pair is optional:

* 'column_family' => The name (string) of the column family to apply the
changes to.

### Examples

    # Writes the key-value pairs 'firstname' => 'Saghm' and
    # 'lastname' => 'Rossi' atomically to the database.
    db_obj.writeBatch([
        {
            put: [ ['firstname', 'Saghm'], ['lastname', 'Rossi'] ]
        }
    ]);


    # Deletes the values associated with 'firstname' and 'lastname' in
    # the default column family and adds the key 'number_of_people' with
    # with the value '2'. Additionally, adds the key-value pair
    # 'name' => 'Saghm Rossi' to the column family 'user1' and the pair
    # 'name' => 'Matt Blaze' to the column family 'user2'. All writes
    # are done atomically.
    db_obj.writeBatch([
        {
            put: [ ['number_of_people', '2'] ],
            delete: ['firstname', 'lastname']
        },
        {
            put: [ ['name', 'Saghm Rossi'] ],
            column_family: 'user1'
        },
        {
            put: [ ['name', Matt Blaze'] ],
            column_family: 'user2'
        }
    ]);