0.1.1 • Published 11 months ago

@s4p/smdb v0.1.1

Weekly downloads
-
License
-
Repository
github
Last release
11 months ago

SMDB

A subset of MongoDB's API (the most used operations) simple database, support mongo / memory / file driver

npm version

How to use

  1. connet to db

    import { SubsetMongo } from '@s4p/smdb';
    import { MongoClient } from 'mongodb';
    import DataStore from '@s4p/nedb';
    
    // mongodb
    const smdb = new SubsetMongo(MongoClient);
    smdb.connect('mongodb://localhost:27017/test', { timestamp: true });
    
    // memory
    const smdb = new SubsetMongo(DataStore, 'memory', { timestamp: true });
    
    // dir (file storage)
    const smdb = new SubsetMongo(DataStore);
    smdb.connect('dir:///some/absolute/dir', { timestamp: true });
    
    // disconnect
    await smdb.disconnect();
  2. create / get collection

    const personCollection = smdb.collection('person');
  3. collection CRUD

    insertOne(doc: OptionalUnlessRequiredId<T>): Promise<InsertOneResult>;
    insertMany(docs: OptionalUnlessRequiredId<T>[]): Promise<InsertManyResult>;
    
    deleteOne(filter: Filter<T>): Promise<DeleteResult>;
    deleteMany(filter: Filter<T>): Promise<DeleteResult>;
    
    updateOne(
      filter: Filter<T>,
      document: UpdateFilter<T>,
      options?: UpdateOptions,
    ): Promise<UpdateResult<T>>;
    updateMany(
      filter: Filter<T>,
      document: UpdateFilter<T>,
      options?: UpdateOptions,
    ): Promise<UpdateResult<T>>;
    
    findOne(query: Filter<T>, options?: FindOptions): Promise<(T & { _id?: any }) | null>;
    find(query: Filter<T>, options?: FindOptions): Promise<WithId<T>[]>;
    
    countDocuments(query?: Filter<T>): Promise<number>;
    
    createIndex(
      fieldOrSpec: IndexSpecification,
      options?: CreateIndexesOptions,
    ): Promise<string>;
    dropIndex(indexName: string): Promise<void>;
    listIndexes(): Promise<ListIndexesResult[]>;
    
    drop(): Promise<boolean>;

Thanks

Nedb

Dev

how to generate MongoDB types

pnpm exec dts-bundle-generator -o my.d.ts ./index.ts --external-inlines mongodb --external-inlines bson

License

MIT

0.1.1

11 months ago

0.1.0

12 months ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago