hebrew / עברית

cnaan aviv

about me

cnaan aviv

Cnaan Aviv

I live in Moshav Gittit. I like writing code, create usefull software and develop interesting projects.
I have recently founded a new StartUp called Make My Day and I am the CTO and Co-founder. In some of my well know projects you can find Kama Kesef - how much money to bring for weddings, or Gematria calculator - an online Gematria value synonymous finder.

You can visit my blog breakpo.com which is mostly about programming items but not only, or see what my company underdog projects developes. You may read short stories I wrote in Hebrew or see some more projects of mine.

Find me on social media, Cnaan Aviv on X (Twitter), on LinkedIn, yabs: @yabs.io Underdog Projects and caviv on github.

Thanks,
Contact me: Cnaan Aviv.

my latest projects

Tiny Sheet Extension | freesheet.io

Tiny Sheet Extension | freesheet.io

A tiny spreadsheet that lives inside your browser and saves data locally. For easy and fast access, when you need to save your data but not to open a new Google sheet. You can also synchronise the data online. - browser, chrome, excel, extension, google, my-tiny-sheet, sheet, spreadsheet, tiny

json2smtp - Connect to your smtp server over json

json2smtp - Connect to your smtp server over json

An online service and opensource project to send emails using json. Creates a proxy where json comes in and smtp calls go out. - email, golang, json, online, php, proxy, service, smtp, tls

web2mail - get a webpage by email

web2mail - get a webpage by email

An email service. Email a website URL in the subject and get a reply by email of this webpage as pdf, png, jpeg and even as html. You can surf the web using your email. Also some configuration like setting the width and height. - convert, email, image, jpg, online, pdf, png, tool

City Skyline Generator - genart

City Skyline Generator - genart

Using computer drawing to create a dystopian city skyline. Made as a learning projects of javascript, canvas, html and part of the “I don't know how to draw“ genart projects to create images using software - art, canvas, city, dystopian, genart, generator, graphics, html, image, javascript, skyline

Teu Sonho Online Interprete Seus Sonhos

Teu Sonho Online Interprete Seus Sonhos

Teusonho.org é um software de interpretatação online de sonhos usando IA para análise em tempo real de sonhos repetidos e símbolos de sonhos. - Analise, analysis, brazil, dream, dream_analysis, dreams, dreams_meaning, dreams_symbols, Meu, portuguese, sonho, teusonho, understandmydreams

9gag RSS - 9gagrss.xyz

9gag RSS - 9gagrss.xyz

Read 9gag.com as RSS, ATOM or JSON - 9gag, 9gag.com, atom, json, rss, tool

Comparison of Coronavirus cases between countries

Comparison of Coronavirus cases between countries

A comparison graph to see the differences of new cases of Corona Virus between world countries, number of new cases and deaths of the coronavirus - compare, corona, coronavirus, countries, data, graph, world

גרף השוואה בן מדינות על התפרצות נגיף הקורונה

גרף השוואה בן מדינות על התפרצות נגיף הקורונה

גרף המאפשר השוואה בין מדינות שונות על פי מספר נדבקים ב וירוס הקורונה, מספר נפטרים - כלל עולמי - analysis, corona, coronavirus, data, virus, worldwide, גרף, דאטא, השוואה, וירוס, מידע, קורונה

Make My Day - Route Planning App

Make My Day - Route Planning App

Make My Day - Route Planning App and Driving assistance for Drivers and Electric Vehicles. Planning Stops, timing and locations for charging. - chargingstations, driver, drivingassistance, electricvehicle, ev, makemyday, route, routeoptimization, routeplanning

אני רוצה דו

אני רוצה דו"ח בנייר

מערכת שמעדכנת את חברות הביטוח וקרנות ההשתלמות בכך שאנחנו מעוניינים לקבל את הדוח השנתי בנייר - , _, hebrew, insurance

meeba social application for travelers - home

meeba social application for travelers - home

with meeba you can meet new people to travel with, discover new places, create and join events, get information wherever you are from people who are there with you. - app, application, discover, events, meeba, meeba-app, meebaapp, meet, people, places, social, travel, travelers, trek, trip

email2json.com - send emails get them as json webhook

email2json.com - send emails get them as json webhook

Email webhook API. Receive your emails as JSON in POST to your specific URL - Create email automation easily - API, automation, email, email2json, json, mail, mail-api, post, webhook

yabs.io - Yet Another Bookmarks Service

yabs.io - Yet Another Bookmarks Service

Smart bookmarks service. Can save bookmarks for long time period between browsers. Tag your bookmarks and search by tags, bundle or free text. - bookmark, bookmarking, bookmarks, browser, links, online, search-engine, service

מחשבון גימטריה עברית

מחשבון גימטריה עברית

מחשבון גימטריה עברית למציאת ביטויי גימטריא מקבילים לפסוקים וביטויים בתנך - מחשבון גימטריה לתוצאות גימטריא עברית ברשת. שווה לכל נפש. חישוב תוצאות גמטריה מהתנ“ך והצגת תוצאות ביטויים מקבילים. - bible, calculator, gematria, gematria_calculator, hebrew, ביטויים, גימטריה, מחשבון, עיברית, תנ“ך

תוכנה לניהול ומעקב אחר הוצאות והכנסות למשק בית

תוכנה לניהול ומעקב אחר הוצאות והכנסות למשק בית

תוכנה לניהול תקציב במשק בית המאפשרת הזנת נתונים אוטומטיים מכל חשבונות הבנק וכרטיסי האשראי ומיצרת גרפים של הכנסות והוצאות עם תובנות וחלוקת הוצאות לקטגוריות. - , aviv, budget, cnaan, expenses, income, online, outcome, software, software-as-a-service

תדירות ישראלית

תדירות ישראלית

תצוגה של סטטיסטיקות והתדירות שלהם במדינת ישראל בצורה ייחודית ומעניינת - hebrew, israel, statistics, ישראל, ישראלית, סטטיסטיקה, פעימות, תדירות

Israel Under Terror

Israel Under Terror

Visualization of Terrorists attacks over Israel, a graph over time of casualties. - attacks, data, east, graph, infographics, israel, middle, terror, terrorism, visualization

Yearly Calendar View

Yearly Calendar View

Agenda like never seen before. It is like Google Maps for your Calendar. Allowing you to see an overview of years, months, weeks and days of your Agenda. You can zoom-in and see details of every day or zoom-out and see your global plans for the summer. This extension uses SVG and HTML5 in a unique matter giving you the option to plan your vacation, to plan your work a head and see your schedule in a very intuitive very easy to use Schedule-Mapping. - agenda, calendar, google, html5, online, schedule, svg, tool, view, year, yearly, zoom

לוח חופשות - Calendar - בתי הספר והגנים - 2014-2015

לוח חופשות - Calendar - בתי הספר והגנים - 2014-2015

הוספת לוח שנה של כל החופשות של בתי הספר והגנים ישירות לתוך גוגל קלנדר או אאוטלוק - calendar, google, israel, school, vacations

jobs trends - ניתוח מגמות למודעות דרושים

jobs trends - ניתוח מגמות למודעות דרושים

ניתוח טרנדים בחיפוש עבודה ומגמות על ציר הזמן במודעות דרושים - עבור חיפוש עבודה - analysis, analyzing, hebrew, israel, job, jobstrends, offer, trends, work, דרושים, חיפוש, טכנולוגיה, ישראל, מודעות, מקצועות, ניתוח, עבודה, קריירה, תחומים, תפקידים

Time and Line a service for creating conjunction time lines

Time and Line a service for creating conjunction time lines

Time and Line, is an online graph application for creating timeline graphs. It is capable to view different units and how those units react together. Like players in a basketball team, players join the group, players leave. - api, application, canvas, graph, graphics, html5, javascript, online, timeline

Analyzed News - News Analysis

Analyzed News - News Analysis

News Analysis tool. Get your news in real time. Parse the articles and understand the news. See the news hot topics and how the time line of the topic last. - analysis, analyzed, analyzing, article, corona, news, online, timeline, tool, topic

Planet Commander Chrome Extension

Planet Commander Chrome Extension

Chrome Extension for the Popular pure HTML5 Javascript Canvas game, Planet Commander, where you need to conquer planets using your space ships and planets. - canvas, chrome, extension, game, games, html5, javascript

Planet Commander

Planet Commander

Planet Commander is an online game written in JavaScript to play and enjoy a mind and real time gaming - canvas, game, games, html5, javascript, online

פענוח חלומות ופרוש חלומות

פענוח חלומות ופרוש חלומות

אתר און-ליין לפירוש חלומות ולהבנת הסמלים המופיעים בחלום - analysis, dream, dreams, hebrew, online, און-ליין, חלום, חלומות, ניתוח, פענוח

News Trends Israel - מחקר חדשות -

News Trends Israel - מחקר חדשות -

מערכת לניתוח ידיעות חדשותיות והצדת ארכיון חדשות על ציר הזמן - feed, israel, news, rss, time, timeline, trends, חדשות, מחקר, קורונה

המסנן - מסנן לך מה שאתה לא רוצה לראות

המסנן - מסנן לך מה שאתה לא רוצה לראות

סינון פרסומות מאתרי חדשות ישראלים וסינון שמאלנים - addon, ads, chrome, commercial, extension, hebrew, israel, ynet, מסנן, סמולנים, פרסומות

New Stage | במה חדשה | Cnaan Aviv | כנען אביב

New Stage | במה חדשה | Cnaan Aviv | כנען אביב

סיפורים קצרים מאת כנען אביב בבמה חדשה - , cnaan, hebrew, stories, story

Build your own Memory Game

Build your own Memory Game

Build your own Memory Game using your own pictures and images, play with it. Pure JavaScript - Make your own memory game online. - build, cnaan, development, free, fun, funny, game, games, javascript, memory, online, programming

LOOP Movie Film

LOOP Movie Film

The short film Loop movie - blog, cnaan, movie, youtube

breakpo.com - בלוג תכנה

breakpo.com - בלוג תכנה

בלוג פיתוח תכנה - , ajax, app, blog, css, development, facebook, html, java, javascript, mfc, mfx, mysql, outsource, php, programming, projects, sql, win32, wtl

Interesting Sites

Interesting Sites

Interesting Sites - for:blog, for:company, for:interesting, for:sites, for:underdo_projects, for:underdog

detectIT.co.il

detectIT.co.il

זיהוי סוסים טרויאניים וחדירות למחשב - מחקר פורנזי - , company, detection, detectit, horses, intrusion, intrusion-detection, trojan, trojan-horses

Interesting Sites

Interesting Sites

Interesting Sites - interesting, sites, underdog, underdog_projects

vetkey.com

vetkey.com

Online veterinary clinics management. Can access files from everywhere for pets owners and treatments. - clinic, online, saas, service, services, software, software-as-a-service, veterinary

cnaanaviv.com

cnaanaviv.com

Follow my projects @cnaanaviv.com - aviv, blog, cnaan, cnaan-aviv, company, development, online, programming, projects, stories, story

Swift Coding

Swift Coding

Israeli software outsourcing company for advanced coding - c, coding, company, css, development, directx, html, israel, javascript, mfx, mysql, outsource, php, wcf, win32, windows, windows7, wpf, wtl

Dreams Interpretation and Analysis Online - Understand my Dreams

Dreams Interpretation and Analysis Online - Understand my Dreams

The meaning of dreams. Understanding the symbols appearing in your dreams and interpret them. - analysis, dream, dream_analysis, dreams, dreams_meaning, dreams_symbols, interpret, meaning, online, sleep, symbols

Gematrix: Gematria Calculator - Word gematira values

Gematrix: Gematria Calculator - Word gematira values

English Gematria, Latin Gematria, Online Gematria Calculator, Hebrew Kaballa Gematria Values Calculator - calculator, english, english_calculatore, gematria, gematria_calculator, gimatria, hebrew, jewish, kabbalah, online

tifsuni.co.il - מאגר הטפסים בעברית

tifsuni.co.il - מאגר הטפסים בעברית

כל הטפסים, טפסי ממשלה, חוזים, טפסי רישום, טופס 101, הורדות טפסים - , 101, 106, download, hebrew, tfasim, tifsuni, tofes, underdog, underdog_projects

VetKey תכנה לניהול מרפאות וטרינריות

VetKey תכנה לניהול מרפאות וטרינריות

תכנה און-ליין לוטרינרים לניהול מרפאות וטרינריות במחשב מכל מקום כולל הנפקת חשבוניות ודיווח כלבת - clinic, clinics, hebrew, managment, online, vet, vetrinar, וטרינריות, מרפאות, ניהול, תכנה

Underdog at GeekCon

Underdog at GeekCon

Underdog Projects for GeekCon 2007,2008 - Cellular mobile using to create a grid computer - cellular, geeconkids, geek_con, geekcon, geekcon08, geekids, grid, kids, mobile, PI, projects, sms, sms2boiler, underdog, underdog_projects, גיקון, קידס

ממיר מספר לטקסט

ממיר מספר לטקסט

ממיר ממספר לטקסט ומטקסט למספר און ליין - convert, converter, hebrew, numbers, online, text, המרה, טקסט, מילים, ממיר, מספר

Encoding Convertor: Command Line Utility

Encoding Convertor: Command Line Utility

Command line utility for windows command line to convert files from any encoding to any encoding - .net, char_set, command, command_line, convert, converter, encoding, line, linux, programming, tool, utf8, windows

מחשבון מע“מ לחשבונית

מחשבון מע“מ לחשבונית

מחשבון online לחישוב מס ערך מוסך לחשבונית. מאפשר הזנת כמה סכומים במקביל ועריכה מכל מקום - calculator, israel, online, useful, vat, און-ליין, חשבונית, ישראל, מערכת

כמה כסף רושמים על השיק לחתונה

כמה כסף רושמים על השיק לחתונה

כמה כסף רושמים על השיק לחתונה - כנען אביב - hebrew, il, israel, money, useful, wedding

Underdog Projects - Israel Software Development

Underdog Projects - Israel Software Development

Underdog Projects - Israel Software Development - android, c, company, contract, development, linux, software, web, win32, windows, wtl, בית-תכנה, ישראל, פיתוח, תכנה

c2kb my projects

c2kb my projects

My Projects - c, company, contract, linux, projects, software, win32, windows, wtl

blog

New: How to connect to mysql database from go - correct way

2026-03-28T10:49:20.260-04:00

 

The dbconnect.go Architecture

In Go, sql.Open doesn't actually connect to the database—it initializes a Pool. This pool is a manager that sits between your code and the database, handing out "check-out" tickets for connections.

1. The Connection (The "Dial")

The DSN string defines the network path. By adding parameters like timeout=30s, you tell the driver how long to wait for the initial handshake before giving up.

2. The Pooling (The "Manager")

By setting SetMaxOpenConns, you create a hard ceiling. If you set it to 10, Go will never attempt an 11th connection. Instead, it makes the next request wait in a queue. SetConnMaxLifetime ensures that old, "stale" connections are killed off before the server (DreamHost) forcibly drops them.

3. The Context (The "Stopwatch")

Using context.WithTimeout is how you control that queue. Without a context, a query might wait forever for a free connection. With a context, you say: "I am willing to wait 5 seconds for a connection; if one doesn't become free by then, cancel the request."

 

The dbconnect.go file that actually runs the connection:

package dbconnect

import (
"context"
"database/sql"
"log/slog"
"time"
"understandmydreams/i18n"

_ "github.com/go-sql-driver/mysql" // Register the driver
)

var oneConnection *sql.DB

// stats := db.Stats()
// fmt.Printf("Open Connections: %d\n", stats.OpenConnections)
// fmt.Printf("In Use: %d\n", stats.InUse)
// fmt.Printf("Idle: %d\n", stats.Idle)
// fmt.Printf("Wait Count: %d\n", stats.WaitCount) // High number here means your app is slow/blocked

func GetConnection(whereFrom string) (*sql.DB, error) {
slog.Info("GetConnection: " + whereFrom)
if oneConnection == nil {
var err error
oneConnection, err = createConnection()
if err != nil {
return nil, err
}
}

// implement ping
// err := db.PingContext(ctx)
// if err != nil {
// slog.Error("Database is unreachable", "err", err)
// // This is where you'd trigger a retry or shut down
// }

return oneConnection, nil
}

// create a real connection to the database
func createConnection() (*sql.DB, error) {
var err error
 
    // ConnectionString: fmt.Sprintf("user:password@tcp(host:3306)/database?charset=utf8mb3&timeout=%ds&readTimeout=%ds&writeTimeout=%ds", MaxExecutionTime, MaxExecutionTime, MaxExecutionTime),    
db, err := sql.Open("mysql", i18n.I18N.ConnectionString)
if err != nil {
slog.Error("20241212.01314 createConnection", "err", err)
return nil, err
}

db.SetMaxOpenConns(50) // Set max open connections
db.SetMaxIdleConns(10) // Set max idle connections
db.SetConnMaxLifetime(time.Second * 120) // Set the max lifetime of a connection

// Create a 5-second deadline for this specific operation
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(i18n.MaxExecutionTime)*time.Second)
defer cancel()

// Setting session-specific parameters
_, err = db.ExecContext(ctx, "SET SESSION max_execution_time=?", i18n.MaxExecutionTime*1000) // milliseconds 30*1000
if err != nil {
slog.Error("20241212.01641 set max_execution_time", "error", err)
return nil, err
}

_, err = db.ExecContext(ctx, "SET SESSION wait_timeout=?", i18n.MaxExecutionTime) // seconds
if err != nil {
slog.Error("20241212.01641 set wait_timeout", "error", err)
return nil, err
}

_, err = db.ExecContext(ctx, "SET SESSION interactive_timeout=?", i18n.MaxExecutionTime) // seconds
if err != nil {
slog.Error("20241212.01642 set interactive_timeout", "error", err)
return nil, err
}

return db, nil
}


 When we need to run a query:


func getMostViewedDreams(limit int) []DreamInfo {
var dreams []DreamInfo = make([]DreamInfo, 0, limit)
db, err := dbconnect.GetConnection("getMostViewedDreams")
if err != nil {
slog.Error("20250209.02158 getMostViewedDreams: connecting to the database", "error", err)
return dreams
}

ctx, cancel := context.WithTimeout(context.Background(), time.Duration(i18n.MaxExecutionTime)*time.Second)
defer cancel()
results, err := db.QueryContext(ctx, "SELECT id,text,views FROM dreams ORDER BY views DESC LIMIT "+fmt.Sprint(limit))
if err != nil {
slog.Error("20250209.02200 getMostViewedDreams: selecting", "error", err)
return dreams
}
defer results.Close()

for results.Next() {
var cw DreamInfo
if err := results.Scan(&cw.Id, &cw.Text, &cw.Views); err != nil {
slog.Error("20250209.02201 getMostViewedDreams", "error", err)
return dreams
}

cw.Summary = textmanipulation.Summarize(cw.Text, " ")

dreams = append(dreams, cw)
}

return dreams
}


 

 

Key Takeaway

  • The Pool prevents you from crashing the database.

  • The Context prevents the database from crashing your app's performance.

  • The Lifetime prevents "Broken Pipe" errors on shared hosting.

 

Read ..

More blog posts ...

contact me

Write what's on your mind: