All Projects → crystal-lang → crystal-mysql

crystal-lang / crystal-mysql

Licence: MIT license
MySQL connector for Crystal

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to crystal-mysql

Xilinx axidma
A zero-copy Linux driver and a userspace interface library for Xilinx's AXI DMA and VDMA IP blocks. These serve as bridges for communication between the processing system and FPGA programmable logic fabric, through one of the DMA ports on the Zynq processing system. Distributed under the MIT License.
Stars: ✭ 251 (+146.08%)
Mutual labels:  driver
ControlBlockService2
This is the driver for the ControlBlock re.v 2.X, a power switch and input/output/gameapd gadget for the Raspberry Pi
Stars: ✭ 18 (-82.35%)
Mutual labels:  driver
BBear balance car
it'a mini auto balance car which use the mini motor to drive the car
Stars: ✭ 44 (-56.86%)
Mutual labels:  driver
phpRebloom
🎛️ Use RedisBloom in PHP!
Stars: ✭ 20 (-80.39%)
Mutual labels:  driver
tarantool-php
PECL PHP driver for Tarantool
Stars: ✭ 82 (-19.61%)
Mutual labels:  driver
fanuc-driver
Configurable Fanuc Focas data collector and post processor.
Stars: ✭ 38 (-62.75%)
Mutual labels:  driver
Ocilib
OCILIB (C and C++ Drivers for Oracle) - Open source C and C++ library for accessing Oracle databases
Stars: ✭ 245 (+140.2%)
Mutual labels:  driver
opendragon
Open Redragon drivers for Linux. Currently only supporting some mice.
Stars: ✭ 72 (-29.41%)
Mutual labels:  driver
aioch
aioch - is a library for accessing a ClickHouse database over native interface from the asyncio
Stars: ✭ 145 (+42.16%)
Mutual labels:  driver
rssd
Rohde & Schwarz SCPI Driver (in Python)
Stars: ✭ 25 (-75.49%)
Mutual labels:  driver
ryzen smu
A Linux kernel driver that exposes access to the SMU (System Management Unit) for certain AMD Ryzen Processors. Read only mirror of https://gitlab.com/leogx9r/ryzen_smu
Stars: ✭ 57 (-44.12%)
Mutual labels:  driver
realtek-uad-nahimic-mod
Realtek Universal Audio Driver with Nahimic APO
Stars: ✭ 55 (-46.08%)
Mutual labels:  driver
influxable
A lightweight python ORM / ODM / Client for InfluxDB
Stars: ✭ 36 (-64.71%)
Mutual labels:  driver
f1-telemetry-client
A Node UDP client and telemetry parser for Codemaster's Formula 1 series of games
Stars: ✭ 128 (+25.49%)
Mutual labels:  driver
r8125-esxi
Realtek RTL8125 driver for ESXi 6.7
Stars: ✭ 163 (+59.8%)
Mutual labels:  driver
Fluffos
Actively maintained LPMUD driver (LPC interpreter, MudOS fork)
Stars: ✭ 249 (+144.12%)
Mutual labels:  driver
theCore
theCore: C++ embedded framework
Stars: ✭ 76 (-25.49%)
Mutual labels:  driver
fluent-provider
A provider for including Fluent in Vapor applications
Stars: ✭ 13 (-87.25%)
Mutual labels:  driver
ridesharing-ios
Ridesharing driver & rider sample apps using HyperTrack SDK
Stars: ✭ 97 (-4.9%)
Mutual labels:  driver
moon c
문c 블로그 with ARM64 Linux Kernel 5.x
Stars: ✭ 17 (-83.33%)
Mutual labels:  driver

crystal-mysql Build Status

MySQL driver implement natively in Crystal, without relying on external libraries.

Check crystal-db for general db driver documentation. crystal-mysql driver is registered under mysql:// uri.

Why

Using a natively implemented library has a significant performance improvement over working with an external library, since there is no need to copy data to and from the Crystal space and the native code. Initial tests with the library have shown a 2x-3x performance boost, though additional testing is required.

Also, going through the MySQL external library blocks the Crystal thread using it, thus imposing a significant penalty to concurrent database accesses, such as those in web servers. We aim to overcome this issue through a full Crystal implementation of the MySQL driver that plays nice with non-blocking IO.

Status

This driver is a work in progress. It implements mysql's binary protocol to create prepared statements. Contributions are most welcome.

Installation

Add this to your application's shard.yml:

dependencies:
  mysql:
    github: crystal-lang/crystal-mysql

Usage

require "mysql"

# connect to localhost mysql test db
DB.open "mysql://root@localhost/test" do |db|
  db.exec "drop table if exists contacts"
  db.exec "create table contacts (name varchar(30), age int)"
  db.exec "insert into contacts values (?, ?)", "John Doe", 30

  args = [] of DB::Any
  args << "Sarah"
  args << 33
  db.exec "insert into contacts values (?, ?)", args: args

  puts "max age:"
  puts db.scalar "select max(age) from contacts" # => 33

  puts "contacts:"
  db.query "select name, age from contacts order by age desc" do |rs|
    puts "#{rs.column_name(0)} (#{rs.column_name(1)})"
    # => name (age)
    rs.each do
      puts "#{rs.read(String)} (#{rs.read(Int32)})"
      # => Sarah (33)
      # => John Doe (30)
    end
  end
end

When running this example, if you get the following exception:

Unhandled exception: Client does not support authentication protocol requested by server; consider upgrading MySQL client (Exception)

You have two options, set a password for root, or (most recommended option) create another user with access to test database.

CREATE USER 'test'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
GRANT ALL PRIVILEGES ON test.* TO 'test'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
quit

Then use the example above changing the DB.open line to

DB.open "mysql://test:yourpassword@localhost/test" do |db|

Connection URI

The connection string has the following syntax:

mysql://[user[:[password]]@]host[:port][/schema][?param1=value1&param2=value2]

Connection query params:

  • encoding: The collation & charset (character set) to use during the connection. If empty or not defined, it will be set to utf8_general_ci. The list of available collations is defined in MySql::Collations::COLLATIONS_IDS_BY_NAME
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].