for _, side in pairs( rs.getSides() ) do
    if peripheral.isPresent( side ) and peripheral.getType( side ) == "ccDB" then
        dbPeriph = peripheral.wrap(side)
        break
    end
end

if not dbPeriph then
    --if term.isColor() then term.setTextColor( colors.red ) end
    -- Just print, because in this CC version if we error then the API will not finish being loaded.
    error("Connecting to ccdb peripheral failed.")
end

function checkAPI()
    if not dbPeriph then
        error("No ccdb peripheral present!\nPlease reboot, place ccdb connector\nnext to computer & reload the API.")
    end
end

function getNewConnection( _sUrl, _sUser, _sPwd )
    checkAPI()
    local nConnID = dbPeriph.getNewConnectionID( _sUrl, _sUser, _sPwd )
    local sConnTbl = dbPeriph.getConnectionTableString( nConnID )
    local getTable = loadstring( sConnTbl )( )
    local tConn = getTable( dbPeriph )
    -- local tConn = dbPeriph.getConnectionTable( nConnID )
    -- Link the peripheral with the connection-table.
    -- tConn.periph = dbPeriph
    return tConn
end

function disconnectAll()
    checkAPI()
    return dbPeriph.disconnectAll()
end

function getVersion()
    checkAPI()
    return dbPeriph.getVersion()
end

function setDebug( bValue )
    checkAPI()
    dbPeriph.setDebug( bValue )
end

function getDebug()
    checkAPI()
    return dbPeriph.getDebug()
end
