@opzlab/library
v1.6.12
Published
Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
Downloads
3
Maintainers
Readme
opzlab/library
Documents
logger
function info(...args: any[])
function warn(...args: any[])
function error(...args: any[])
function log(...args: any[])
jsonfiles
set default caches_folder in the environment file '.env'
CACHES_FOLDER = 'caches'
const networks
const objectTemplate
const arrayTemplate
async function loadJson(template: any, filename: string)
async function storeJson(JsonObject: any, filename: string)
async function renameJson(srcfile: string, dscfile: string)
async function removeJson(filenames: string[])
dotenv
async function updateEnvVariable(key: string, value: any)
async function verifyEnvPath()
Use verifyEnvPath to add default '.env' as follows
SHUTDOWNTIMEOUT = 5000
AZURE_STORAGE_CONNECTION_STRING = "DefaultEndpointsProtocol=https;AccountName=opzlife;AccountKey=LOdony4b3rontTCRXyPh6Gna5aJhelonGSWitbbd3+8kSBe46ZAEbn2lL9Xsw3IwA5f/0xS3XhJp+AStUVBkxA==;EndpointSuffix=core.windows.net"
CACHES_FOLDER = caches
POSTGRES_USER= dev
POSTGRES_PASSWORD = dev
POSTGRES_DB = workermainnet
SERVER_PORT = 5432
AZ_CONTAINER = opzlab
storage
set default caches_folder in the environment file '.env'
AZURE_STORAGE_CONNECTION_STRING = "Def..."
AZ_CONTAINER = opzlab
class datastore {
async removeFolder(){}
async removeContainer(){}
async block_push(files: string[]){}
async block_pull(files: string[]){}
}
postgresql
connections there are 2 connections for [0] default postgres [1] current as '.env'
type connection = {
name:string,
db:any
}
const connections:connection[] =[2]
install
async function installPostgreSqlIfNotExist()
async function uninstallPostgreSQLUbuntu()
user
async function userCreate(username: string, passwd: string)
async function userDrop(userName: string)
async function userIsExist(username: string)
async function userArray()
database
async function dbCreate(dbname: string)
async function dbDrop(dbName: string)
async function dbIsExist(dbname: string)
async function dbNameArray()
async function dbGrantToUser(dbname: string, username: string)
async function dbRevokeToUser(dbname: string, username: string)
async function dbGrantee()
table
async function tableCommand(sqlcommand:string)
async function tableList()
async function tableDrop(tableName: string)
async function tableDetail(tableName: string)
async function tableRecords(tableName:string,offset:number,limit:number)
async function tableRecordsbyId(tableName:string,orderby:string,offset:number,limit:number)
block
async function createBlockTable()
async function insertBlock(model: Block)
async function updateBlock(model: Block)
async function deleteBlock(id: number)
async function detailBlockTable(tableName: string)
sample of use
const logger = require('@opzlab/library')
const {networks,objectTemplate,arrayTemplate,loadJson,storeJson} = require('@opzlab/library')
logger.info('Current working directory:', process.cwd())
console.log(networks)
console.log(objectTemplate)
console.log(arrayTemplate)
loadJson(arrayTemplate,'testfile').then((d)=>{
logger.info(d)
storeJson(d,'test2')
});
install prostgresql
sudo apt update
sudo apt install postgresql postgresql-contrib
psql --version
sudo service postgresql start
service postgresql status
```
start as 'postgres' and create password for postgres = 'password'
```
sudo -u postgres psql
postgres=# ALTER USER postgres PASSWORD 'password';
postgres=# \q
```
list all users and role
```
postgres=# \du
postgres=# \q
```
try create user name $USER
```
postgres=# CREATE ROLE chaiya LOGIN SUPERUSER CREATEDB CREATEROLE REPLICATION BYPASSRLS PASSWORD 'password';
postgres=# \du
postgres=# DROP ROLE chaiya;
postgres=# \du
postgres=# \q
sudo -u postgres psql -c "CREATE USER admin WITH PASSWORD 'password';"
```
# sample
```
cd ~
sudo -u postgres createdb workermainnet
cd ~
sudo -u postgres psql -c "CREATE USER dev WITH PASSWORD 'dev';"
cd ~
sudo -u postgres psql -c "grant all privileges on database workermainnet to dev;"
```