async findOne(
    filter,
  ) {
    for await (
      const file of Deno.readDir(
        Deno.realPathSync(`${this.sabr.directoryPath}${this.name}`),
      )
    ) {
      if (!file.name || !file.isFile) continue;
      try {
        // Substring remove the file type `.json` from file.name
        const name = file.name.substring(0, file.name.lastIndexOf("."));
        const json = await this.get(name);
        if (json) {
          if (typeof filter === "function") {
            if (filter(json)) return json;
          } else {
            const invalid = Object.keys(filter).find((key) =>
              json[key] !== filter[key]
            );
            if (!invalid) return json;
          }
        }
      } catch (error) {
        this.sabr.error(
          `[Sabr Error: findOne]: Unable to read file ${this.sabr.directoryPath}${this.name}/${file.name}`,
          error,
        );
      }
    }
  }
/** Gets the first document from a table that match a filter */
Gets the first document from a table that match a filter
Gets the first document from a table that match a filter
async findOne(
    filter,
  ) {
    for await (
      const file of Deno.readDir(
        Deno.realPathSync(`${this.sabr.directoryPath}${this.name}`),
      )
    ) {
      if (!file.name || !file.isFile) continue;
      try {
        const name = file.name.substring(0, file.name.lastIndexOf("."));
        const json = await this.get(name);
        if (json) {
          if (typeof filter === "function") {
            if (filter(json)) return json;
          } else {
            const invalid = Object.keys(filter).find((key) =>
              json[key] !== filter[key]
            );
            if (!invalid) return json;
          }
        }
      } catch (error) {
        this.sabr.error(
          `[Sabr Error: findOne]: Unable to read file ${this.sabr.directoryPath}${this.name}/${file.name}`,
          error,
        );
      }
    }
  }
async findOne ( filter , ) { for await ( const file of Deno . readDir ( Deno . realPathSync ( ` ${ this . sabr . directoryPath } ${ this . name } ` ) , ) ) { if ( ! file . name || ! file . isFile ) continue ; try { const name = file . name . substring ( 0 , file . name . lastIndexOf ( "." ) ) ; const json = await this . get ( name ) ; if ( json ) { if ( typeof filter === "function" ) { if ( filter ( json ) ) return json ; } else { const invalid = Object . keys ( filter ) . find ( ( key ) => json [ key ] !== filter [ key ] ) ; if ( ! invalid ) return json ; } } } catch ( error ) { this . sabr . error ( ` ${ this . sabr . directoryPath } ${ this . name } ${ file . name } ` , error , ) ; } } }
Gets the first document from a table that match a filter
Gets the first document from a table that match a filter
// Substring remove the file type `.json` from file.name