Arangodb- does a data dictionary Exist - arangodb

does anyone know if arangodb has any sort of data dictionary available ? In essence we’re responsible for reporting and it would be helpful to be able to run a query that would enable us to list of collection and attributes so we can see has been been added/removed/updated ?
Basically an equivalent of all_tab_columns in oracle would be helpful .
Thanks

You could use arangosh command (more) and list all collections in a database using db._collections(). Then you can run a query that goes through every document in a collection and gets its ATTRIBUTES (source).
Example bash script:
#!/bin/bash
read -p "Database: " DATABASE
read -p "Username: " USERNAME
read -s -p "Password: " PASSWORD
echo
ARANGOSH_SCRIPT=$(cat <<-END
const getAttributes = (collection) => db._query(\`
FOR rec IN \${collection}
FOR attr IN ATTRIBUTES(rec)
RETURN DISTINCT attr
\`).toArray();
db._collections().forEach((collection) => {
if (collection.properties().isSystem) {
// ignore system collections
return;
}
const collectionName = collection.name();
print(\`\${collectionName}: \${JSON.stringify(getAttributes(collectionName))}\`);
});
END
)
arangosh --server.database "$DATABASE" \
--server.username "$USERNAME" \
--server.password "$PASSWORD" \
--javascript.execute-string "$ARANGOSH_SCRIPT"

Related

How to dynamically build Postgres query from API parameters in Nodejs?

I'm looking for a way to dynamically build a SQL query for an unknown number of API parameters that may come back. As a simple example, consider the following query:
router.get("/someEndpoint", authorizationFunction, async (req, res) => {
let sql = `
SELECT *
FROM some_table
WHERE username = $1
${req.query.since !== undefined ? "AND hire_date >= $2" : ""}
`
const results = await pool.query(sql, [req.query.user, req.query.since]);
}
where pool is defined as
const Pool = require("pg").Pool;
const pool = new Pool({<connection parameters>});
The problem I'm having is that if req.query.since is not provided, then the SQL query only requires a single bound parameter ($1). This is presented as an error that says bind message supplies 2 parameters, but prepared statement "" requires 1. Since I don't know which parameters a user will provide until the time of the query, I'm under the impression that I need to provide all possible value, and let the query figure it out.
I've seen a lot of posts that point to pg-promise as a solution, but I'm wondering if that's necessary. Is there a way that I can solve this with my current setup? Perhaps I'm thinking about the problem incorrectly?
Thanks in advance!
Add a trivial expression text that contains $2 and evaluates to true instead of "", for example
SELECT * FROM some_table WHERE username = $1 AND
${req.query.since !== undefined ? " hire_date >= $2": " (true or $2 = $2)"}
The planner will remove it anyway. Added true or just in case $2 is null.
Still it would be cleaner like this
if (req.query.since !== undefined)
{
let sql = `SELECT * FROM some_table WHERE username = $1 AND hire_date >= $2`;
const results = await pool.query(sql, [req.query.user, req.query.since]);
}
else
{
let sql = `SELECT * FROM some_table WHERE username = $1`;
const results = await pool.query(sql, [req.query.user]);
}
What about SQLi risk BTW?

Check Whether Directory Exists In Remote Server For Perl

I wish to check whether a path given is exists or is a directory in another site server in Perl. My code is as below.
my $destination_path = "<path>";
my $ssh = "usr/bin/ssh";
my $user_id = getpwuid( $< );
my $site = "<site_name>";
my $host = "rsync.$site.com";
if ($ssh $user_id\#$host [-d $destination_path]){
print "Is a directory.\n";
}
else{
print "Is not a directory.\n";
}
I am sure my code is wrong as I modify the code according to bash example I see from another question but I have no clue how to fix it. Thanks for everyone that helps here.
[ is the name of a command, and it must be separated from other words on the command line. So just use more spaces:
$ssh $user\#$host [ -d $destination_path ]
To actually execute this command, you'll want to use the builtin system function. system returns 0 when the command it executes is successful (see the docs at the link)
if (0 == system("$ssh $user\#$host [ -d $destination_path ]")) {
print "Is a directory.\n";
} else {
print "Is not a directory.\n";
}
Accessing the remote file system through SFTP:
use Net::SFTP::Foreign;
$sftp = Net::SFTP::Foreign->new("rsync.$site.com");
if ($sftp->test_d($destination_path)) {
"print $destination_path is a directory!\n";
}

searching for a word in expect output

I have an expect command
expect "~]#" { send "virsh list --all\r"}
and the output would be
[root#lht1oneems-unit0 ~]# virsh list --all
Id Name State
----------------------------------------------------
399 lht1duplexvm-0 running
- rhelvm shut off
I want to use $expect_out(buffer) and have an if statement to do something if it finds running and do something else if not.
how can I parse into the result of $expect_out(buffer)?
expect "~]#"
send "virsh list --all\r"
# I assume another prompt follows this
expect "~]#"
if { [regexp {running} $expect_out(buffer)] } {
do-something-for-running-process
} else {
do-something-for-no-running-process
}
You could also do
if {[string first "running" $expect_out(buffer)] >= 0} {

Webforms in excel instead of e-mail

A client of mine asked me if i can find a solution for this problem.
His website (still a WIP) http://welkommagazine.nl/luuk/ has a form. The form obviously uses a sendmail script to send the form to e-mail. From thereon he manually copy/pastes all the submissions to excel.
What he wants is that the forms online automaticcaly are added to an excel document to save him a lot of work.
Now i am not a programmer, but a designer.. I think this can be done, but i have absolutely no clue how. I googled alot for it and the only thing i found was a dreamweaverplugin.
Is there a way to do this, if so, how?
Not a programmer's response, but...
I think an easy solution is to use Google docs. You can set-up a Google Spreadsheet and associate a form to it. Whenever a user fills the form , his data is added to the spreadsheet.
Your client may download that anytime.
There are some other providers on the market, some free, some not. E.g: wufoo.com
Found the answer myself. I wrote a PHP code snippet which actually stores the fields comma seperated in a CSV file and sends an email to a desired adress with the filled in fields.
if(isset($_POST['Submit'])){
$pakket = $_POST['pakket'];
$extragidsen = $_POST['extragidsen'];
$naambedrijf = $_POST['naambedrijf'];
$err = '';
if(trim($pakket)==''){
$err .= '-Please enter a name';
}
if(empty($extragidsen)){
$err .= '-Please enter an email address';
}
if(strlen($naambedrijf)==0){
$err .= '-Please enter a comment';
}
if($err!=''){
echo $err;
}
else{
$filename = 'file.csv';
$somecontent = $pakket . ',' . $extragidsen . ',' . $naambedrijf . "\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
//--------------------------Set these paramaters--------------------------
// Subject of email sent to you.
$subject = 'Inschrijving welkom';
// Your email address. This is where the form information will be sent.
$emailadd = 'luuk#luukratief.com';
// Where to redirect after form is processed.
$url = 'http://www.google.com';
// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';
// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i ';
fclose($handle);
} else {
echo "The file $filename is not writable";
}
}
}
Maybe the code aint that clean as it can be, but eh it works.
Feel free to clean up the code if you want to :)
I guessed I would answer this myself for the community...
BTW u need to set "write" rights to "file.csv"
cheers

Kohana 3 ORM find_all() returns all rows regardless of where clause

I have one simple users table, and I want to find all users where email_notifications = 1.
Logic dictates that the following should work:
class Controller_Test extends Controller {
public function action_index()
{
$user = ORM::factory('user');
$user = $user->where('email_notifications', '=', 1);
$total = $user->count_all();
$users = $user->find_all();
echo $total." records found.<br/>";
foreach ($users as $v)
{
echo $v->id;
echo $v->first_name;
echo $v->last_name;
echo $v->email;
}
}
}
However, what's happening is that I am getting ALL of my users back from the DB, not just the ones with email_notifications turned on. The funny thing is, the $total value returned is the accurate number result of this query.
I am so stumped, I have no idea what the problem is here. If anyone could shed some light, I'd really appreciate it.
Thanks,
Brian
Calling count_all() will reset your model conditions. Try to use reset(FALSE) to avoid this:
$user = ORM::factory('user');
$user = $user->where('email_notifications', '=', 1);
$user->reset(FALSE);
$total = $user->count_all();
$users = $user->find_all();

Resources