3. Set Up Database
const db = createNodeDatabase('./path/to/database');const db = createWebDatabase('./data/mydb');const db = await createNativeDatabase('/path/to/database');
// Setup for Node builds.
import LevelDownDB from "leveldown";
/**
* Creates a LevelDown database instance at the specified path.
*
* @param dbLocationPath - The file system path where the database will be created
* @returns A LevelDown database instance
*
* @example
* ```typescript
* const db = createNodeDatabase('./path/to/database');
* ```
*/
export const createNodeDatabase = (dbLocationPath: string) => {
console.log("Creating local database at path: ", dbLocationPath);
const db = LevelDownDB(dbLocationPath);
return db;
};
// Setup for Web builds.
import LevelDB from "level-js";
/**
* Creates a new web database instance at the specified location path
* @param dbLocationPath - The file system path where the database will be created
* @returns A new LevelDB database instance
* @remarks This function initializes a new LevelDB database at the specified path
* and provides basic database functionality through the returned instance.
* @example
* const db = createWebDatabase('./data/mydb');
*/
export const createWebDatabase = (dbLocationPath: string) => {
indexedDB.databases;
console.log("Creating local database at path: ", dbLocationPath);
const db = new LevelDB(dbLocationPath);
return db;
};
// Setup for React Native builds.
// @ts-ignore
import LeveldownNodejsMobile from "leveldown-nodejs-mobile";
/**
* Creates a native database instance using LeveldownNodejsMobile.
*
* @param dbLocationPath - The file system path where the database will be stored
* @returns A Promise that resolves to a new LeveldownNodejsMobile database instance
*
* @example
* ```typescript
* const db = await createNativeDatabase('/path/to/database');
* ```
*/
export const createNativeDatabase = async (dbLocationPath: string) => {
return new LeveldownNodejsMobile(dbLocationPath);
};Previous2. Setting up networks and RPC providersNext4. Build a persistent store for artifact downloads
Last updated