You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package will introduce a layer that appears to be a single database but behind the scenes actually communicates with any number of database. Similar to how the pgsql/mssql packages have a createDatabase function this package will have one that returns a Database object.
Features:
Horizontal & vertical scaling
Horizontal scaling via sharding, meaning an algorithm can take a query parameter and tell you which databases you can look in to find that data.
Vertical scaling via specifying read & write databases.
Seamless use, if a query is analyzed and it reaches across databases it will run it on each one and then bring it together and process the results into a single result. Ideally all queries resolve to a single database, but sometimes that's unavailable. The package will communicate what databases will be required.
The package can have a dynamic list of databases, so as the user scales up they don't need to restart their server with updated code.
Examples:
import{createScaleDatabase,WriteStrategy,ReadStrategy,DatabaseStrategy,Shard}from'@typed-query-builder/scale';import{createDatabase}from'@typed-query-builder/pgsql';// Vertical scaling with one write and multiple readsconstdb=createScaleDatabase({databaseStrategy: DatabaseStrategy.DYNAMIC,// CACHEDgetDatabase: async(name: string)=>createDatabase(/* connection */),databases: {},// alternative to getDatabase, specify a fixed map of databases by their namewriteStrategy: WriteStrategy.ALL,// ROUND_ROBIN, LEAST_USED, ALL, or a functiongetWrites: async(meta)=>['main_database'],writes: [],// alternative to getWrites, specify a fixed array of write databaseswritesByTable: {},// map of which database to write to based on the table.readStrategy: ReadStrategy.ROUND_ROBIN,// LEAST_USED, or a functiongetReads: async(meta)=>['read_1','read_2','read_3'],reads: [],// alternative to getReads, specify a fixed array of read databasesreadsByTable: {},mapofwhichdatabasetoreadfrombasedonthe table
});// Horizontal scalingconstdb=createScaleDatabase({databases: {shard_1: createDatabase(/* connection */),shard_2: createDatabase(/* connection */),shard_3: createDatabase(/* connection */),},// generates reading and writing options defined in the vertical scaling example. may need to rethink design.shard: {user: Shard.byRange({column: 'user_id',ranges: async()=>({shard_1: [1,10000],shard_2: [10001,20000],shard_3: [20000,100000000],}),insert: async(props)=>'shard_3',}),},});
The text was updated successfully, but these errors were encountered:
This package will introduce a layer that appears to be a single database but behind the scenes actually communicates with any number of database. Similar to how the pgsql/mssql packages have a createDatabase function this package will have one that returns a Database object.
Features:
Examples:
The text was updated successfully, but these errors were encountered: