DuckDB C# (Geliştiriciler İçin Nasıl Çalışır)
DuckDB.NET, DuckDB yerel kütüphanesi için .NET bağlayıcıları sağlayan açık kaynaklı bir sağlayıcıdır ve C# ile sorunsuz bir şekilde entegre edilmek üzere tasarlanmıştır. ADO.NET sağlayıcısı sunar, bu da DuckDB, düşük seviye bağlayıcılar kütüphanesini, .NET uygulamaları içinde kullanmayı kolaylaştırır. Bu paket, DuckDB'nin güçlü analitik yeteneklerinden yararlanmak isteyen geliştiriciler için ideal bir çözümdür.
Kurulum
DuckDB.NET'in kurulumu basittir. .NET CLI kullanarak projenize ekleyebilirsiniz:
dotnet add package DuckDB.NET.Data.Full
dotnet add package DuckDB.NET.Data.Full
Alternatif olarak, Visual Studio'daki NuGet Paket Yöneticisi aracılığıyla yükleyebilirsiniz.
Temel Kullanım
Kurulum tamamlandıktan sonra, C# uygulamanızda SQL sorgularını yürütmek için DuckDB.NET'i kullanmaya başlayabilirsiniz. İşte basit bir örnek:
using System;
using DuckDB.NET.Data;
class Program
{
static void Main()
{
// Create and open a connection to an in-memory DuckDB database
using var duckdbconnection = new DuckDBConnection("Data Source=:memory:");
duckdbconnection.Open();
// Create a command associated with the connection
using var command = duckdbconnection.CreateCommand();
// Create a table named 'integers'
command.CommandText = "CREATE TABLE integers(foo INTEGER, bar INTEGER);";
command.ExecuteNonQuery();
// Insert some data into the 'integers' table
command.CommandText = "INSERT INTO integers VALUES (3, 4), (5, 6), (7, 8);";
command.ExecuteNonQuery();
// Retrieve the count of rows in the 'integers' table
command.CommandText = "SELECT count(*) FROM integers";
var executeScalar = command.ExecuteScalar();
// Select all values from the 'integers' table
command.CommandText = "SELECT foo, bar FROM integers;";
// Execute the query and process the results
using var reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine($"{reader.GetInt32(0)}, {reader.GetInt32(1)}");
}
}
}
using System;
using DuckDB.NET.Data;
class Program
{
static void Main()
{
// Create and open a connection to an in-memory DuckDB database
using var duckdbconnection = new DuckDBConnection("Data Source=:memory:");
duckdbconnection.Open();
// Create a command associated with the connection
using var command = duckdbconnection.CreateCommand();
// Create a table named 'integers'
command.CommandText = "CREATE TABLE integers(foo INTEGER, bar INTEGER);";
command.ExecuteNonQuery();
// Insert some data into the 'integers' table
command.CommandText = "INSERT INTO integers VALUES (3, 4), (5, 6), (7, 8);";
command.ExecuteNonQuery();
// Retrieve the count of rows in the 'integers' table
command.CommandText = "SELECT count(*) FROM integers";
var executeScalar = command.ExecuteScalar();
// Select all values from the 'integers' table
command.CommandText = "SELECT foo, bar FROM integers;";
// Execute the query and process the results
using var reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine($"{reader.GetInt32(0)}, {reader.GetInt32(1)}");
}
}
}
Imports System
Imports DuckDB.NET.Data
Friend Class Program
Shared Sub Main()
' Create and open a connection to an in-memory DuckDB database
Dim duckdbconnection As New DuckDBConnection("Data Source=:memory:")
duckdbconnection.Open()
' Create a command associated with the connection
Dim command = duckdbconnection.CreateCommand()
' Create a table named 'integers'
command.CommandText = "CREATE TABLE integers(foo INTEGER, bar INTEGER);"
command.ExecuteNonQuery()
' Insert some data into the 'integers' table
command.CommandText = "INSERT INTO integers VALUES (3, 4), (5, 6), (7, 8);"
command.ExecuteNonQuery()
' Retrieve the count of rows in the 'integers' table
command.CommandText = "SELECT count(*) FROM integers"
Dim executeScalar = command.ExecuteScalar()
' Select all values from the 'integers' table
command.CommandText = "SELECT foo, bar FROM integers;"
' Execute the query and process the results
Dim reader = command.ExecuteReader()
Do While reader.Read()
Console.WriteLine($"{reader.GetInt32(0)}, {reader.GetInt32(1)}")
Loop
End Sub
End Class
Bu örnek, DuckDB.NET kullanarak bir tablo oluşturma, veri ekleme ve veriyi sorgulama işlemlerini gösterir.
Çıktı

Veri Alımı
DuckDB.NET, CSV ve Parquet dosyaları dahil olmak üzere çeşitli formatlardan veri okumayı destekler. Bir CSV dosyasından veri nasıl okuyabileceğiniz şöyle:
command.CommandText = "COPY integers FROM 'example.csv' (FORMAT CSV);";
command.ExecuteNonQuery();
command.CommandText = "COPY integers FROM 'example.csv' (FORMAT CSV);";
command.ExecuteNonQuery();
command.CommandText = "COPY integers FROM 'example.csv' (FORMAT CSV)"
command.ExecuteNonQuery()
DataFrames ile Entegrasyon
DuckDB.NET, veri çerçeveleri ile de entegre olabilir ve tanıdık SQL sözlüğünü kullanarak veri manipülasyonu yapmanıza olanak tanır. Bu, özellikle veri analizi görevleri için kullanışlıdır.
Sonuç Dönüşümü
Sorgu sonuçlarını listeler veya özel nesneler gibi çeşitli formatlara dönüştürebilir, bu da uygulamanızda verilerle çalışmayı kolaylaştırır:
var results = new List<(int foo, int bar)>();
// Read and store results to a List
while (reader.Read())
{
results.Add((reader.GetInt32(0), reader.GetInt32(1)));
// You can also use a loop with an index to iterate the results
}
var results = new List<(int foo, int bar)>();
// Read and store results to a List
while (reader.Read())
{
results.Add((reader.GetInt32(0), reader.GetInt32(1)));
// You can also use a loop with an index to iterate the results
}
Dim results = New List(Of (foo As Integer, bar As Integer))()
' Read and store results to a List
Do While reader.Read()
results.Add((reader.GetInt32(0), reader.GetInt32(1)))
' You can also use a loop with an index to iterate the results
Loop
Disk'e Veri Yazma
DuckDB.NET, diske çeşitli formatlarda veri yazmayı destekler. Verileri bir CSV dosyasına aktarmak için KOPYALA ifadesini kullanabilirsiniz:
command.CommandText = "COPY integers TO 'output.csv' (FORMAT CSV);";
command.ExecuteNonQuery();
command.CommandText = "COPY integers TO 'output.csv' (FORMAT CSV);";
command.ExecuteNonQuery();
command.CommandText = "COPY integers TO 'output.csv' (FORMAT CSV)"
command.ExecuteNonQuery()
IronPDF'ye Giriş

IronPDF, .NET projelerinde PDF belgelerini oluşturma, yönetme ve içerik çıkarma olanağı sunan bir C# PDF kütüphanesidir. İşte bazı temel özellikler:
IronPDF, web sayfalarını, URL'leri ve HTML'i PDF'e Dönüştürmenizi sağlayan kullanışlı bir araçtır. En iyi kısmı? PDF'ler orijinal web sayfalarına tamamen benzer – tüm biçimlendirme ve stil korunarak. Dolayısıyla, çevrimiçi bir rapor veya fatura gibi bir şeyden PDF oluşturmanız gerekiyorsa, IronPDF sizin tercih edeceğiniz araçtır.
using IronPdf;
class Program
{
static void Main(string[] args)
{
var renderer = new ChromePdfRenderer();
// 1. Convert HTML String to PDF
var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>";
var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent);
pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf");
// 2. Convert HTML File to PDF
var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file
var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath);
pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf");
// 3. Convert URL to PDF
var url = "http://ironpdf.com"; // Specify the URL
var pdfFromUrl = renderer.RenderUrlAsPdf(url);
pdfFromUrl.SaveAs("URLToPDF.pdf");
}
}
using IronPdf;
class Program
{
static void Main(string[] args)
{
var renderer = new ChromePdfRenderer();
// 1. Convert HTML String to PDF
var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>";
var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent);
pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf");
// 2. Convert HTML File to PDF
var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file
var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath);
pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf");
// 3. Convert URL to PDF
var url = "http://ironpdf.com"; // Specify the URL
var pdfFromUrl = renderer.RenderUrlAsPdf(url);
pdfFromUrl.SaveAs("URLToPDF.pdf");
}
}
Imports IronPdf
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim renderer = New ChromePdfRenderer()
' 1. Convert HTML String to PDF
Dim htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"
Dim pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent)
pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf")
' 2. Convert HTML File to PDF
Dim htmlFilePath = "path_to_your_html_file.html" ' Specify the path to your HTML file
Dim pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath)
pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf")
' 3. Convert URL to PDF
Dim url = "http://ironpdf.com" ' Specify the URL
Dim pdfFromUrl = renderer.RenderUrlAsPdf(url)
pdfFromUrl.SaveAs("URLToPDF.pdf")
End Sub
End Class
-
HTML'den PDF'ye Dönüştürme:
- HTML, CSS ve JavaScript içeriğini PDF'lere dönüştürün.
- Piksel mükemmel PDF belgeleri için Chrome İşleme Motoru.
- URL'lerden, HTML dosyalarından veya HTML dizelerinden PDF üretin.
-
Görüntü ve İçerik Dönüştürme:
- Görüntüleri PDF belgelerine ve PDF belgelerinden dönüştürün.
- Mevcut PDF belgelerinden metin ve görüntü çıkarın.
- JPG, PNG gibi çeşitli görüntü formatlarına destek.
-
Düzenleme ve Manipülasyon:
- PDF belgeleri için özellikler, güvenlik ve izinleri ayarlayın.
- PDF'lere dijital imzalar ekleyin.
- Meta verileri ve revizyon geçmişini düzenleyin.
- Çapraz Platform Desteği:
- .NET Core (8, 7, 6, 5, ve 3.1+), .NET Standard (2.0+), ve .NET Framework (4.6.2+) ile çalışır.
- Windows, Linux ve macOS ile uyumludur.
- Kolay kurulum için NuGet üzerinde mevcuttur.
IronPDF ve DuckDB .NET Kullanarak PDF Belgeleri Oluşturun
Başlangıç olarak, aşağıda olduğu gibi Visual Studio kullanarak bir Console uygulaması oluşturun.

Proje adını sağlayın.

.NET Sürümünü sağlayın.

IronPDF paketini yükleyin.

DuckDB.NET paketini yükleyin.

using DuckDB.NET.Data;
using IronPdf;
namespace CodeSample
{
public static class DuckDbDemo
{
public static void Execute()
{
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
var content = "<h1>Demo DuckDb and IronPDF</h1>";
content += "<h2>Create DuckDBConnection</h2>";
content += "<p>new DuckDBConnection(\"Data Source=:memory:\");</p>";
content += "<p></p>";
// Create and open a connection to an in-memory DuckDB database
using var connection = new DuckDBConnection("Data Source=:memory:");
connection.Open();
using var command = connection.CreateCommand();
// Create a table named 'integers'
command.CommandText = "CREATE TABLE integers(book STRING, cost INTEGER);";
command.ExecuteNonQuery();
content += "<p>CREATE TABLE integers(book STRING, cost INTEGER);</p>";
// Insert some data into the 'integers' table
command.CommandText = "INSERT INTO integers VALUES ('book1', 25), ('book2', 30), ('book3', 10);";
command.ExecuteNonQuery();
content += "<p>INSERT INTO integers VALUES ('book1', 25), ('book2', 30), ('book3', 10);</p>";
// Select all values from the 'integers' table
command.CommandText = "SELECT book, cost FROM integers;";
using var reader = command.ExecuteReader();
content += "<p>SELECT book, cost FROM integers;</p>";
// Execute the query and process the results, appending them to the HTML content
while (reader.Read())
{
content += $"<p>{reader.GetString(0)}, {reader.GetInt32(1)}</p>";
Console.WriteLine($"{reader.GetString(0)}, {reader.GetInt32(1)}");
}
// Save data to CSV
content += "<p>Save data to CSV with COPY integers TO 'output.csv' (FORMAT CSV);</p>";
command.CommandText = "COPY integers TO 'output.csv' (FORMAT CSV);";
command.ExecuteNonQuery();
// Generate and save PDF
var pdf = renderer.RenderHtmlAsPdf(content);
pdf.SaveAs("AwesomeDuckDbNet.pdf");
}
}
}
using DuckDB.NET.Data;
using IronPdf;
namespace CodeSample
{
public static class DuckDbDemo
{
public static void Execute()
{
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
var content = "<h1>Demo DuckDb and IronPDF</h1>";
content += "<h2>Create DuckDBConnection</h2>";
content += "<p>new DuckDBConnection(\"Data Source=:memory:\");</p>";
content += "<p></p>";
// Create and open a connection to an in-memory DuckDB database
using var connection = new DuckDBConnection("Data Source=:memory:");
connection.Open();
using var command = connection.CreateCommand();
// Create a table named 'integers'
command.CommandText = "CREATE TABLE integers(book STRING, cost INTEGER);";
command.ExecuteNonQuery();
content += "<p>CREATE TABLE integers(book STRING, cost INTEGER);</p>";
// Insert some data into the 'integers' table
command.CommandText = "INSERT INTO integers VALUES ('book1', 25), ('book2', 30), ('book3', 10);";
command.ExecuteNonQuery();
content += "<p>INSERT INTO integers VALUES ('book1', 25), ('book2', 30), ('book3', 10);</p>";
// Select all values from the 'integers' table
command.CommandText = "SELECT book, cost FROM integers;";
using var reader = command.ExecuteReader();
content += "<p>SELECT book, cost FROM integers;</p>";
// Execute the query and process the results, appending them to the HTML content
while (reader.Read())
{
content += $"<p>{reader.GetString(0)}, {reader.GetInt32(1)}</p>";
Console.WriteLine($"{reader.GetString(0)}, {reader.GetInt32(1)}");
}
// Save data to CSV
content += "<p>Save data to CSV with COPY integers TO 'output.csv' (FORMAT CSV);</p>";
command.CommandText = "COPY integers TO 'output.csv' (FORMAT CSV);";
command.ExecuteNonQuery();
// Generate and save PDF
var pdf = renderer.RenderHtmlAsPdf(content);
pdf.SaveAs("AwesomeDuckDbNet.pdf");
}
}
}
Imports DuckDB.NET.Data
Imports IronPdf
Namespace CodeSample
Public Module DuckDbDemo
Public Sub Execute()
' Instantiate Renderer
Dim renderer = New ChromePdfRenderer()
Dim content = "<h1>Demo DuckDb and IronPDF</h1>"
content &= "<h2>Create DuckDBConnection</h2>"
content &= "<p>new DuckDBConnection(""Data Source=:memory:"");</p>"
content &= "<p></p>"
' Create and open a connection to an in-memory DuckDB database
Dim connection = New DuckDBConnection("Data Source=:memory:")
connection.Open()
Dim command = connection.CreateCommand()
' Create a table named 'integers'
command.CommandText = "CREATE TABLE integers(book STRING, cost INTEGER);"
command.ExecuteNonQuery()
content &= "<p>CREATE TABLE integers(book STRING, cost INTEGER);</p>"
' Insert some data into the 'integers' table
command.CommandText = "INSERT INTO integers VALUES ('book1', 25), ('book2', 30), ('book3', 10);"
command.ExecuteNonQuery()
content &= "<p>INSERT INTO integers VALUES ('book1', 25), ('book2', 30), ('book3', 10);</p>"
' Select all values from the 'integers' table
command.CommandText = "SELECT book, cost FROM integers;"
Dim reader = command.ExecuteReader()
content &= "<p>SELECT book, cost FROM integers;</p>"
' Execute the query and process the results, appending them to the HTML content
Do While reader.Read()
content &= $"<p>{reader.GetString(0)}, {reader.GetInt32(1)}</p>"
Console.WriteLine($"{reader.GetString(0)}, {reader.GetInt32(1)}")
Loop
' Save data to CSV
content &= "<p>Save data to CSV with COPY integers TO 'output.csv' (FORMAT CSV);</p>"
command.CommandText = "COPY integers TO 'output.csv' (FORMAT CSV);"
command.ExecuteNonQuery()
' Generate and save PDF
Dim pdf = renderer.RenderHtmlAsPdf(content)
pdf.SaveAs("AwesomeDuckDbNet.pdf")
End Sub
End Module
End Namespace
Kod Açıklaması
Kod, DuckDB.NET'i veritabanı işlemleri için ve IronPDF'i veritabanı sorgu sonuçlarını içeren bir PDF raporu üretmek için nasıl kullanılacağını göstermeyi amaçlar.
Temel Bileşenler
-
DuckDB.NET:
- DuckDBConnection: Bellek içi bir DuckDB veritabanı dosyasına bağlantı kurar ("Data Source=:memory:"). Bu bağlantı, SQL komutlarını yürütmek için kod boyunca kullanılır.
-
Veritabanı İşlemleri:
- Tablo Oluşturma: book (STRING) ve cost (INTEGER) sütunlarına sahip integers adlı bir tablo oluşturmak için bir SQL komutu (CREATE TABLE integers(book STRING, cost INTEGER);) tanımlar.
- Veri Ekleme: integers tablosuna satırlar ekler (INSERT INTO integers VALUES ('book1', 25), ('book2', 30), ('book3', 10);).
- Veri Alma: integers tablosundan veri almak için bir SELECT sorgusu (SELECT book, cost FROM integers;) yürütür. Alınan veriler HTML (content) formatına dönüştürülür ve konsola yazdırılır.
- IronPDF ile PDF Oluşturma:
- HTML'yi PDF'e Dönüştürme: IronPDF'ten ChromePdfRenderer kullanarak HTML içeriğini (content) bir PDF belgesine (pdf) dönüştürür.
- PDF'i Kaydetme: Üretilen PDF'i mevcut dizinde "AwesomeDuckDbNet.pdf" olarak kaydeder.
Çıktı


IronPDF Lisanslama
IronPDF paketi çalışmak için bir lisansa ihtiyaç duyar. Pakete erişilmeden önce uygulamanın başına aşağıdaki kodu ekleyin.
IronPdf.License.LicenseKey = "IRONPDF-KEY";
IronPdf.License.LicenseKey = "IRONPDF-KEY";
Imports IronPdf
IronPdf.License.LicenseKey = "IRONPDF-KEY"
Bir deneme lisansı IronPDF'in deneme lisans sayfasında mevcuttur.
Sonuç
DuckDB.NET C# paketi, DuckDB'nin analitik yeteneklerini .NET uygulamalarına entegre etmek için güçlü bir araçtır. Kullanım kolaylığı, çeşitli veri formatları desteği ve C# ile sorunsuz entegrasyonu, onu veri yoğun uygulamalarda çalışan geliştiriciler için mükemmel bir seçim haline getirir. Veri analiz araçları, ETL hatları veya başka veri odaklı uygulamalar oluşturuyor olun, DuckDB.NET hedeflerinizi verimli bir şekilde gerçekleştirmenize yardımcı olabilir.
Sıkça Sorulan Sorular
DuckDB.NET, C# uygulamalarında ne için kullanılır?
DuckDB.NET, DuckDB yerel kütüphanesini C# uygulamalarına entegre etmek için kullanılır; geliştiricilere güçlü analitik yetenekler ADO.NET sağlayıcısı aracılığıyla sunar.
C# projesinde DuckDB.NET nasıl kurabilirim?
DuckDB.NET'i .NET CLI komutunu dotnet add package DuckDB.NET.Data.Full kullanarak veya Visual Studio'daki NuGet Paket Yöneticisi aracılığıyla kurabilirsiniz.
DuckDB.NET kullanarak SQL sorgularını nasıl çalıştırabilirim?
DuckDBConnection ile bir bağlantı kurarak ve tablolar oluşturmak, veri eklemek ve veri almak için SQL komutlarını çalıştırarak DuckDB.NET ile SQL sorgularını çalıştırabilirsiniz.
DuckDB.NET, CSV ve Parquet dosyalarından veri okumayı destekliyor mu?
Evet, DuckDB.NET, çeşitli formatlardan veri alımını destekler, CSV ve Parquet dosyaları da dahil olmak üzere, bu veri türlerinin C# uygulamalarında kesintisiz entegrasyonuna ve manipülasyonuna olanak tanır.
HTML'yi C# içerisinde PDF'ye nasıl dönüştürebilirim?
HTML dizgilerini PDF'lere dönüştürmek için IronPDF'ün RenderHtmlAsPdf yöntemini kullanabilirsiniz. Ayrıca, HTML dosyalarını RenderHtmlFileAsPdf kullanarak PDF'lere dönüştürebilirsiniz.
Veri yoğun projeler için DuckDB.NET kullanmanın yararları nelerdir?
DuckDB.NET, güçlü analitik yetenekler sunar, SQL tabanlı veri işlemlerini destekler ve C# uygulamalarıyla kolayca entegre olur, bu da onu veri yoğun projeler için ideal bir seçenek haline getirir.
DuckDB.NET veri çerçeveleri ile nasıl entegre edilebilir?
DuckDB.NET, özellikle karmaşık veri analiz görevlerini gerçekleştirmek için yararlı olan SQL tabanlı veri manipülasyonu sağlayarak veri çerçeveleri ile entegre olabilir.
DuckDB.NET kullanarak bir CSV dosyasına nasıl veri aktarabilirim?
DuckDB.NET ile COPY komutunu kullanarak bir CSV dosyasına veri aktarabilirsiniz. Örneğin, COPY integers TO 'output.csv' (FORMAT CSV); kullanarak tablo verilerini bir CSV dosyasına aktarabilirsiniz.
IronPDF hangi platformları destekler?
IronPDF, .NET Core (8, 7, 6, 5, ve 3.1+), .NET Standard (2.0+) ve .NET Framework (4.6.2+)'ü destekler ve Windows, Linux ve macOS ile uyumludur.
DuckDB.NET ve IronPDF'yi raporlar oluşturmak için birleştirebilir miyim?
Evet, DuckDB'nin veritabanı yeteneklerini IronPDF'nin PDF oluşturma özellikleriyle birleştirerek, veri tabanı işlemleri için DuckDB.NET'i ve rapor oluşturma için IronPDF'yi kullanabilirsiniz.




