Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Update examples #610

Merged
merged 2 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions SUPPORTED_CLIENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ These are the clients we actively test against to check are compatible with go-m
import pymysql.cursors

connection = pymysql.connect(host='127.0.0.1',
user='user',
password='pass',
db='db',
user='root',
password='',
db='gitbase',
cursorclass=pymysql.cursors.DictCursor)

try:
with connection.cursor() as cursor:
sql = "SELECT foo FROM bar"
sql = "SELECT * FROM commit_files LIMIT 1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are go-mysql-server examples, not gitbase examples. I don't think we should mix the two of them

cursor.execute(sql)
rows = cursor.fetchall()

Expand All @@ -50,14 +50,14 @@ finally:
import mysql.connector

connection = mysql.connector.connect(host='127.0.0.1',
user='user',
passwd='pass',
user='root',
passwd='',
port=3306,
database='dbname')
database='gitbase')

try:
cursor = connection.cursor()
sql = "SELECT foo FROM bar"
sql = "SELECT * FROM commit_files LIMIT 1"
cursor.execute(sql)
rows = cursor.fetchall()

Expand All @@ -72,9 +72,9 @@ finally:
import pandas as pd
import sqlalchemy

engine = sqlalchemy.create_engine('mysql+pymysql://user:pass@127.0.0.1:3306/dbname')
engine = sqlalchemy.create_engine('mysql+pymysql://root:@127.0.0.1:3306/gitbase')
with engine.connect() as conn:
repo_df = pd.read_sql_table("mytable", con=conn)
repo_df = pd.read_sql_table("commit_files", con=conn)
for table_name in repo_df.to_dict():
print(table_name)
```
Expand All @@ -84,8 +84,8 @@ with engine.connect() as conn:
```ruby
require "mysql"

conn = Mysql::new("127.0.0.1", "user", "pass", "dbname")
resp = conn.query "SELECT foo FROM bar"
conn = Mysql::new("127.0.0.1", "root", "", "gitbase")
resp = conn.query "SELECT * FROM commit_files LIMIT 1"

# use resp

Expand All @@ -96,10 +96,10 @@ conn.close()

```php
try {
$conn = new PDO("mysql:host=127.0.0.1:3306;dbname=dbname", "user", "pass");
$conn = new PDO("mysql:host=127.0.0.1:3306;dbname=gitbase", "root", "");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $conn->query('SELECT foo FROM bar');
$stmt = $conn->query('SELECT * FROM commit_files LIMIT 1');
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

// use result
Expand All @@ -116,13 +116,13 @@ import mysql from 'mysql';
const connection = mysql.createConnection({
host: '127.0.0.1',
port: 3306,
user: 'user',
password: 'pass',
database: 'dbname'
user: 'root',
password: '',
database: 'gitbase'
});
connection.connect();

const query = 'SELECT foo FROM bar';
const query = 'SELECT * FROM commit_files LIMIT 1';
connection.query(query, function (error, results, _) {
if (error) throw error;

Expand All @@ -144,13 +144,13 @@ namespace something
{
public async Task DoQuery()
{
var connectionString = "server=127.0.0.1;user id=user;password=pass;port=3306;database=dbname;";
var connectionString = "server=127.0.0.1;user id=root;password=;port=3306;database=gitbase;";

using (var conn = new MySqlConnection(connectionString))
{
await conn.OpenAsync();

var sql = "SELECT foo FROM bar";
var sql = "SELECT * FROM commit_files LIMIT 1";

using (var cmd = new MySqlCommand(sql, conn))
using (var reader = await cmd.ExecuteReaderAsync())
Expand All @@ -172,8 +172,8 @@ import java.sql.*;

class Main {
public static void main(String[] args) {
String dbUrl = "jdbc:mariadb://127.0.0.1:3306/dbname?user=user&password=pass";
String query = "SELECT foo FROM bar";
String dbUrl = "jdbc:mariadb://127.0.0.1:3306/gitbase?user=root&password=";
String query = "SELECT * FROM commit_files LIMIT 1";

try (Connection connection = DriverManager.getConnection(dbUrl)) {
try (PreparedStatement stmt = connection.prepareStatement(query)) {
Expand Down Expand Up @@ -202,16 +202,16 @@ import (
)

func main() {
db, err := sql.Open("mysql", "user:pass@tcp(127.0.0.1:3306)/test")
db, err := sql.Open("mysql", "root:@tcp(127.0.0.1:3306)/gitbase")
if err != nil {
// handle error
}

rows, err := db.Query("SELECT foo FROM bar")
rows, err := db.Query("SELECT * FROM commit_files LIMIT 1")
if err != nil {
// handle error
}

// use rows
}
```
```
4 changes: 2 additions & 2 deletions _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
config := server.Config{
Protocol: "tcp",
Address: "localhost:3306",
Auth: auth.NewNativeSingle("user", "pass", auth.AllPermissions),
Auth: auth.NewNativeSingle("root", "", auth.AllPermissions),
}

s, err := server.NewDefaultServer(config, engine)
Expand All @@ -44,7 +44,7 @@ func main() {

func createTestDatabase() *mem.Database {
const (
dbName = "test"
dbName = "gitbase"
tableName = "mytable"
)

Expand Down
4 changes: 2 additions & 2 deletions _integration/dotnet/MySQLTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public class MySQLTest
[TestMethod]
public async Task TestCanConnect()
{
var connectionString = "server=127.0.0.1;user id=user;password=pass;port=3306;database=db;";
var connectionString = "server=127.0.0.1;user id=root;password=;port=3306;database=gitbase;";
var expected = new string[][]{
new string[]{"Evil Bob", "evilbob@gmail.com"},
new string[]{"Jane Doe", "jane@doe.com"},
new string[]{"John Doe", "john@doe.com"},
new string[]{"John Doe", "johnalt@doe.com"},
};

using (var conn = new MySqlConnection(connectionString))
{
await conn.OpenAsync();
Expand Down
2 changes: 1 addition & 1 deletion _integration/go/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
_ "github.com/go-sql-driver/mysql"
)

const connectionString = "user:pass@tcp(127.0.0.1:3306)/test"
const connectionString = "root:@tcp(127.0.0.1:3306)/gitbase"

func TestMySQL(t *testing.T) {
db, err := sql.Open("mysql", connectionString)
Expand Down
8 changes: 4 additions & 4 deletions _integration/javascript/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ test.cb('can connect to go-mysql-server', t => {
const connection = mysql.createConnection({
host: '127.0.0.1',
port: 3306,
user: 'user',
password: 'pass',
database: 'db'
user: 'root',
password: '',
database: 'gitbase'
});

connection.connect();
Expand All @@ -29,4 +29,4 @@ test.cb('can connect to go-mysql-server', t => {
});

connection.end();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MySQLTest {

@Test
void test() {
String dbUrl = "jdbc:mariadb://127.0.0.1:3306/db?user=user&password=pass";
String dbUrl = "jdbc:mariadb://127.0.0.1:3306/gitbase?user=root&password=";
String query = "SELECT name, email FROM mytable ORDER BY name, email";
List<Result> expected = new ArrayList<>();
expected.add(new Result("Evil Bob", "evilbob@gmail.com"));
Expand Down
4 changes: 2 additions & 2 deletions _integration/php/tests/MySQLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final class MySQLTest extends TestCase
{
public function testConnection(): void {
try {
$conn = new PDO("mysql:host=127.0.0.1:3306;dbname=db", "user", "pass");
$conn = new PDO("mysql:host=127.0.0.1:3306;dbname=gitbase", "root", "");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $conn->query('SELECT name, email FROM mytable ORDER BY name, email');
Expand All @@ -25,4 +25,4 @@ public function testConnection(): void {
$this->assertFalse(true, $e->getMessage());
}
}
}
}
6 changes: 3 additions & 3 deletions _integration/python-mysql/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class TestMySQL(unittest.TestCase):

def test_connect(self):
connection = mysql.connector.connect(host='127.0.0.1',
user='user',
passwd='pass')
user='root',
passwd='')

try:
cursor = connection.cursor()
Expand All @@ -27,4 +27,4 @@ def test_connect(self):


if __name__ == '__main__':
unittest.main()
unittest.main()
8 changes: 4 additions & 4 deletions _integration/python-pymysql/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class TestMySQL(unittest.TestCase):

def test_connect(self):
connection = pymysql.connect(host='127.0.0.1',
user='user',
password='pass',
db='db',
user='root',
password='',
db='',
cursorclass=pymysql.cursors.DictCursor)

try:
Expand All @@ -29,4 +29,4 @@ def test_connect(self):


if __name__ == '__main__':
unittest.main()
unittest.main()
10 changes: 5 additions & 5 deletions _integration/python-sqlalchemy/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
class TestMySQL(unittest.TestCase):

def test_connect(self):
engine = sqlalchemy.create_engine('mysql+pymysql://user:pass@127.0.0.1:3306/test')
engine = sqlalchemy.create_engine('mysql+pymysql://root:@127.0.0.1:3306/gitbase')
with engine.connect() as conn:
expected = {
"name": {0: 'John Doe', 1: 'John Doe', 2: 'Jane Doe', 3: 'Evil Bob'},
"email": {0: 'john@doe.com', 1: 'johnalt@doe.com', 2: 'jane@doe.com', 3: 'evilbob@gmail.com'},
"phone_numbers": {0: '["555-555-555"]', 1: '[]', 2: '[]', 3: '["555-666-555","666-666-666"]'},
"created_at": {0: pd.Timestamp('2019-01-28 15:35:51'), 1: pd.Timestamp('2019-01-28 15:35:51'), 2: pd.Timestamp('2019-01-28 15:35:51'), 3: pd.Timestamp('2019-01-28 15:35:51')},
}

repo_df = pd.read_sql_table("mytable", con=conn)

self.assertEqual(expected, repo_df.to_dict())
d = repo_df.to_dict()
del d["created_at"]
self.assertEqual(expected, d)


if __name__ == '__main__':
unittest.main()
unittest.main()
6 changes: 3 additions & 3 deletions _integration/ruby/mysql_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class TestMySQL < Minitest::Test
def test_can_connect
conn = Mysql::new("127.0.0.1", "user", "pass")
conn = Mysql::new("127.0.0.1", "root", "")
res = conn.query "SELECT name, email FROM mytable ORDER BY name, email"

expected = [
Expand All @@ -15,7 +15,7 @@ def test_can_connect

rows = res.map do |row| [row[0], row[1]] end
assert_equal rows, expected

conn.close()
end
end
end
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy