Skip to main content
Version: 1.18.x

Bucket

Defined in: Bucket.ts:27

Represents a bucket in ReductStore

Constructors​

Constructor​

> new Bucket(name, httpClient): Bucket

Defined in: Bucket.ts:38

Create a bucket. Use Client.creatBucket or Client.getBucket instead it

Parameters​

name​

string

httpClient​

HttpClient

Returns​

Bucket

See​

Methods​

beginRead()​

> beginRead(entry, ts?, head?): Promise<ReadableRecord>

Defined in: Bucket.ts:234

Start reading a record from an entry

Parameters​

entry​

string

name of the entry

ts?​

bigint

{BigInt} timestamp of record in microseconds. Get the latest one, if undefined

boolean

{boolean} return only head of the record

Returns​

Promise<ReadableRecord>

Promise<ReadableRecord>


beginRemoveBatch()​

> beginRemoveBatch(entry): Promise&lt;Batch&gt;

Defined in: Bucket.ts:122

Remove a batch of records

Parameters​

entry​

string

{string} name of the entry

Returns​

Promise&lt;Batch&gt;


beginRemoveRecordBatch()​

> beginRemoveRecordBatch(): RecordBatch

Defined in: Bucket.ts:479

Create a new batch for removing records across multiple entries.

Returns​

RecordBatch


beginUpdateBatch()​

> beginUpdateBatch(entry): Promise&lt;Batch&gt;

Defined in: Bucket.ts:460

Create a new batch for updating records in the database.

Parameters​

entry​

string

Returns​

Promise&lt;Batch&gt;


beginUpdateRecordBatch()​

> beginUpdateRecordBatch(): RecordBatch

Defined in: Bucket.ts:472

Create a new batch for updating records across multiple entries.

Returns​

RecordBatch

Example​

const batch = bucket.beginUpdateRecordBatch();
batch.addOnlyLabels("entry-1", 1000n, { label1: "value1", label2: "" });
batch.addOnlyLabels("entry-2", 2000n, { label1: "value2" });
await batch.send();

beginWrite()​

> beginWrite(entry, options?): Promise&lt;WritableRecord&gt;

Defined in: Bucket.ts:185

Start writing a record into an entry

Parameters​

entry​

string

name of the entry

options?​

{BigInt | WriteOptions} timestamp in microseconds for the record or options. It is current time if undefined.

bigint | WriteOptions

Returns​

Promise&lt;WritableRecord&gt;

Promise<WritableRecord>

Example​

const record = await bucket.beginWrite("entry", {
ts: 12345667n
labels: {label1: "value1", label2: "value2"}
contentType: "text/plain"
);
await record.write("Hello!");

beginWriteBatch()​

> beginWriteBatch(entry): Promise&lt;Batch&gt;

Defined in: Bucket.ts:440

Create a new batch for writing records to the database.

Parameters​

entry​

string

Returns​

Promise&lt;Batch&gt;


beginWriteRecordBatch()​

> beginWriteRecordBatch(): RecordBatch

Defined in: Bucket.ts:452

Create a new batch for writing records to multiple entries.

Returns​

RecordBatch

Example​

const batch = await bucket.beginWriteRecordBatch();
batch.add("entry-1", 1000n, "data");
batch.add("entry-2", 2000n, "data");
await batch.send();

> createQueryLink(entry, start?, stop?, query?, recordIndex?, expireAt?, fileName?, baseUrl?): Promise&lt;string&gt;

Defined in: Bucket.ts:494

Create a query link for downloading records

Parameters​

entry​

name of the entry or entries

string | string[]

start?​

bigint

start point of the time period for the query

stop?​

bigint

stop point of the time period for the query

query?​

QueryOptions

options for the query

recordIndex?​

number

index of the record to download (0 for the first record, 1 for the second, etc.)

expireAt?​

Date

expiration time of the link. Default is 24 hours from now

fileName?​

string

name of the file to download. Default is $&#123;entry&#125;_$&#123;recordIndex&#125;.bin or $&#123;bucket&#125;_$&#123;recordIndex&#125;.bin for multi-entry

baseUrl?​

string

base url for link generation. If not set, the server's base url will be used

Returns​

Promise&lt;string&gt;


getEntryList()​

> getEntryList(): Promise&lt;EntryInfo[]&gt;

Defined in: Bucket.ts:82

Get entry list

Returns​

Promise&lt;EntryInfo[]&gt;

Async​


getInfo()​

> getInfo(): Promise&lt;BucketInfo&gt;

Defined in: Bucket.ts:72

Get information about a bucket

Returns​

Promise&lt;BucketInfo&gt;

Async​


getName()​

> getName(): string

Defined in: Bucket.ts:351

Returns​

string


getSettings()​

> getSettings(): Promise&lt;BucketSettings&gt;

Defined in: Bucket.ts:50

Get bucket settings

Returns​

Promise&lt;BucketSettings&gt;

Async​


query()​

> query(entry, start?, stop?, options?): AsyncGenerator&lt;ReadableRecord&gt;

Defined in: Bucket.ts:296

Query records for a time interval as generator

Parameters​

entry​

{string | string[]} name of the entry or entries

string | string[]

start?​

bigint

{BigInt} start point of the time period

stop?​

bigint

{BigInt} stop point of the time period

options?​

QueryOptions

{QueryOptions} options options for query

Returns​

AsyncGenerator&lt;ReadableRecord&gt;

Example​

for await (const record in bucket.query("entry-1", start, stop)) {
console.log(record.ts, record.size);
console.log(record.labels);
const content = await record.read();
// or use pipe
const fileStream = fs.createWriteStream(`ts_${record.size}.txt`);
record.pipe(fileStream);
}

remove()​

> remove(): Promise&lt;void&gt;

Defined in: Bucket.ts:94

Remove bucket

Returns​

Promise&lt;void&gt;

Async​


removeEntry()​

> removeEntry(entry): Promise&lt;void&gt;

Defined in: Bucket.ts:104

Remove an entry

Parameters​

entry​

string

{string} name of the entry

Returns​

Promise&lt;void&gt;

Async​


removeQuery()​

> removeQuery(entry, start?, stop?, options?): Promise&lt;number&gt;

Defined in: Bucket.ts:133

Remove records by query

Parameters​

entry​

{string | string[]} name of the entry or entries

string | string[]

start?​

bigint

{BigInt} start point of the time period, if undefined, the query starts from the first record

stop?​

bigint

{BigInt} stop point of the time period. If undefined, the query stops at the last record

options?​

QueryOptions

{QueryOptions} options for query. You can use only include, exclude, eachS, eachN other options are ignored

Returns​

Promise&lt;number&gt;


removeRecord()​

> removeRecord(entry, ts): Promise&lt;void&gt;

Defined in: Bucket.ts:113

Remove a record

Parameters​

entry​

string

{string} name of the entry

ts​

bigint

{BigInt} timestamp of record in microseconds

Returns​

Promise&lt;void&gt;


rename()​

> rename(newName): Promise&lt;void&gt;

Defined in: Bucket.ts:267

Rename a bucket

Parameters​

newName​

string

new name of the bucket

Returns​

Promise&lt;void&gt;


renameEntry()​

> renameEntry(entry, newEntry): Promise&lt;void&gt;

Defined in: Bucket.ts:251

Rename an entry

Parameters​

entry​

string

entry name to rename

newEntry​

string

new entry name

Returns​

Promise&lt;void&gt;


setSettings()​

> setSettings(settings): Promise&lt;void&gt;

Defined in: Bucket.ts:60

Set bucket settings

Parameters​

settings​

BucketSettings

{BucketSettings} new settings (you can set a part of settings)

Returns​

Promise&lt;void&gt;

Async​


update()​

> update(entry, ts, labels): Promise&lt;void&gt;

Defined in: Bucket.ts:213

Update labels of an existing record

If a label has empty string value, it will be removed.

Parameters​

entry​

string

{string} name of the entry

ts​

bigint

{BigInt} timestamp of record in microseconds

labels​

LabelMap

{LabelMap} labels to update

Returns​

Promise&lt;void&gt;