استخدام صندوق PostgreSQL مع MariaDB Xpand

I’m not an anti-GUI person. In fact, I wrote three books about web GUI development with Java. However, I also like the command-line interface (CLI), especially text-based UIs. After a year of exploring MariaDB and the DevOps world, I got to discover and play with many text-based CLI tools that I didn’t know even existed. These tools are especially useful when connecting to remote servers that don’t have a GUI.

أحد الأدوات الأساسية التي أستخدمها بشكل متكرر هو جهاز التحكم في الخوارزميات mariadb SQL client (أو mysql في عالم MySQL) – وهو برنامج سطر الأوامر يستخدم للاتصال بقواعد البيانات متوافقة مع MariaDB. باستخدامه، يمكنك إرسال استعلامات SQL وأوامر أخرى إلى خادم قاعدة البيانات.

جهاز التحكم في الخوارزميات MariaDB المبني على SQL CLI

يتمتع جهاز التحكم في الخوارزميات mariadb SQL بعدة خيارات التكوين، أحدها هو إمكانية تعيين جهاز لمساعدة المستخدم في التصفح. إذا كنت مطلعًا على Linux، ربما كنت قد سمعت أو استخدمت جهازي التصفح more و less. يمكنك تعيين جهاز تصفح من خلال متغير البيئة PAGER وسيستخدم mariadb ذلك تلقائيًا. وبديلًا، يمكنك تعيين جهاز تصفح فقط للجلسة الحالية باستخدام موجه mariadb. على سبيل المثال، لاستخدام جهاز التصفح less استخدم الأمر التالي بمجرد الاتصال بقاعدة البيانات:

MariaDB SQL

 

pager less

في المرة القادمة التي تقوم فيها بتشغيل استعلام SQL، ستتمكن من التنقل في مجموعة النتائج باستخدام مفاتيح السهم على لوحة المفاتيح.

تعيين جهاز تصفح باستخدام جهاز التحكم في الخوارزميات mariadb SQL

مرحبًا بك في محاولة تجربة pspg لعرض مجموعات نتائج SQL كجداول. pspg هو أداة مفتوحة المصدر (راجع الوثائق وشفرة المصدر على GitHub)، التي تم تطويرها في البداية لـ PostgreSQL ولكنها اكتسبت لاحقًا دعمًا لعدة أنظمة قوات الدفاع الشعبي أخرى، بما في ذلك MariaDB. نظرًا لأن عميل mariadb SQL قادر على الاتصال بقوات الدفاع الشعبي MariaDB Xpand، حاولت استخدامه، وعمل بشكل مثالي. استمر في القراءة لمعرفة كيفية التجربة.

أسهل طريقة لتشغيل قاعدة بيانات Xpand هي إنشاء خدمة على SkySQL (إنها مجانية). ومع ذلك، يمكنك أيضًا تشغيل مثيل محلي باستخدام Docker. إليك المقطع الذي تحتاجه:

Shell

 

docker run --name xpand \
  -d \
  -p 3306:3306 \
  --ulimit memlock=-1 \
  mariadb/xpand-single

القوات الدفاعية تكون أكثر متعة عندما يكون هناك بيانات فيها. قاعدة بيانات توضيحية بسيطة ومثيرة للاهتمام متاحة على هذا الموقع. على أنظمة يعتمد عليها Linux، قم بتشغيل الأوامر التالية (تغيير عنوان IP في الأمر الأخير إذا كانت قاعدة بيانات Xpand تعمل في مكان آخر):

Shell

 

sudo apt install curl -y
curl https://www.mariadbtutorial.com/wp-content/uploads/2019/10/nation.zip --output nation.zip
unzip nation.zip
mariadb -h 127.0.0.1 -u xpand < nation.sql
rm nation.zip nation.sql

تذكر تثبيت pspg:

Shell

 

apt install pspg -y

قم بالاتصال بقاعدة البيانات باستخدام عميل SQL mariadb مع مطور واجهة المستخدم الخاصة والأكثر برودة تظهر “Xpand”:

Shell

 

mariadb -h 127.0.0.1 -u xpand --prompt="Xpand [\d]> " nation

I learned this tip from my colleague Patrick Bossman (Product Manager at MariaDB) during a webinar on MariaDB Xpand + Docker. I recommend watching it if you want to learn more.

الاتصال بـ MariaDB Xpand عن طريق موضوع موجه

تعيين مرشح pspg للجلسة الحالية:

MariaDB SQL

 

pager pspg -s 14 -X --force-uniborder --quit-if-one-screen

A nice feature in pspg is that it shows the fancy text-based UI only when it makes sense (--quit-if-one-screen). So if your query returns only a few rows that fit in the screen, it will just show them right there on the screen as usual. For example, try running the following query:

MariaDB SQL

 

select * from continents;

لا شيء جديد لرؤيته هنا.

لن يتم تنشيط مرشح pspg إذا تم عرض عدد قليل فقط من الصفوف

ومع ذلك، جرب ما يلي:

MariaDB SQL

 

select * from countries;

A navigable text-based interface allows you to explore the data more efficiently.

تقديم مرشح pspg بالبيانات من MariaDB Xpand

يمكنك البحث عن صف، والفرز، وتصدير إلى CSV، وتجميد الأعمدة، وتحديد الصفوف، وحتى استخدام الماوس للتفاعل مع الأداة، من بين أمور أخرى.

بعض خيارات القائمة فيpspg

I hope this tool helps you the next time you have to interact with a database via SSH and the command line. You can find more information about how to install pspg on your operating system, configuration options, and documentation on the GitHub repository for the project. If you want to learn more about distributed SQL and the MariaDB Xpand database, watch this short video, take a look at this datasheet, and explore some of the blog posts and documentation.

Source:
https://dzone.com/articles/using-the-postgressql-pager-with-mariadb-xpand