Skip to main content
Version: 1.18.x

Bucket Module

Classes

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<Batch>

Defined in: Bucket.ts:122

Remove a batch of records

Parameters
entry

string

{string} name of the entry

Returns

Promise<Batch>


beginRemoveRecordBatch()

> beginRemoveRecordBatch(): RecordBatch

Defined in: Bucket.ts:479

Create a new batch for removing records across multiple entries.

Returns

RecordBatch


beginUpdateBatch()

> beginUpdateBatch(entry): Promise<Batch>

Defined in: Bucket.ts:460

Create a new batch for updating records in the database.

Parameters
entry

string

Returns

Promise<Batch>


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<WritableRecord>

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<WritableRecord>

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<Batch>

Defined in: Bucket.ts:440

Create a new batch for writing records to the database.

Parameters
entry

string

Returns

Promise<Batch>


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<string>

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<string>


getEntryList()

> getEntryList(): Promise<EntryInfo[]>

Defined in: Bucket.ts:82

Get entry list

Returns

Promise<EntryInfo[]>

Async

getInfo()

> getInfo(): Promise<BucketInfo>

Defined in: Bucket.ts:72

Get information about a bucket

Returns

Promise<BucketInfo>

Async

getName()

> getName(): string

Defined in: Bucket.ts:351

Returns

string


getSettings()

> getSettings(): Promise<BucketSettings>

Defined in: Bucket.ts:50

Get bucket settings

Returns

Promise<BucketSettings>

Async

query()

> query(entry, start?, stop?, options?): AsyncGenerator<ReadableRecord>

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<ReadableRecord>

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<void>

Defined in: Bucket.ts:94

Remove bucket

Returns

Promise<void>

Async

removeEntry()

> removeEntry(entry): Promise<void>

Defined in: Bucket.ts:104

Remove an entry

Parameters
entry

string

{string} name of the entry

Returns

Promise<void>

Async

removeQuery()

> removeQuery(entry, start?, stop?, options?): Promise<number>

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<number>


removeRecord()

> removeRecord(entry, ts): Promise<void>

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<void>


rename()

> rename(newName): Promise<void>

Defined in: Bucket.ts:267

Rename a bucket

Parameters
newName

string

new name of the bucket

Returns

Promise<void>


renameEntry()

> renameEntry(entry, newEntry): Promise<void>

Defined in: Bucket.ts:251

Rename an entry

Parameters
entry

string

entry name to rename

newEntry

string

new entry name

Returns

Promise<void>


setSettings()

> setSettings(settings): Promise<void>

Defined in: Bucket.ts:60

Set bucket settings

Parameters
settings

BucketSettings

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

Returns

Promise<void>

Async

update()

> update(entry, ts, labels): Promise<void>

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<void>

Interfaces

WriteOptions

Defined in: Bucket.ts:18

Options for writing records

Properties

contentType?

> optional contentType: string

Defined in: Bucket.ts:21


labels?

> optional labels: LabelMap

Defined in: Bucket.ts:20


ts?

> optional ts: bigint

Defined in: Bucket.ts:19