Skip to content

A simple solution for importing and synchronizing CBE data into Oracle, Postgres, SQL Server, or any other database. CBE is the English acronym for Kruispuntbank van Ondernemingen (KBO) or Banque-Carrefour des Entreprises (BCE).

License

Notifications You must be signed in to change notification settings

vivarni/Vivarni.CBE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

106 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vivarni.CBE

A simple, practical solution to import and synchronize KBO/BCE/CBE data to your own database (e.g., SQL Server, Postgres, Sqlite, Oracle, ...). It provides clear source abstractions and replaceable storage backends. The acronym CBE stand for "Crossroads Bank for Enterprises in Belgium", and is also known as:

  • Dutch: Kruispuntbank van Ondernemingen
  • French: Banque-Carrefour des Entreprises
  • German: Zentrale Datenbank der Unternehmen

CBE data is provided by the Belgian Governement and is publicly available: https://economie.fgov.be/

Have a local copy of CBE data; synchronized daily

1️⃣ Pull data from the official sources of the Belgian Governement.
2️⃣ Maybe cache the files somewhere, using some storage available.
3️⃣ Store the actual data in a database/storage of your liking
4️⃣ Use it in your code as a repository, EF Core DbSet, or service

Quickstart 🚀

This section shows a simplified, but concrete example of how the package can be used to create a simple that —ultimately— allows you to search CBE data locally. We have other examples in the samples directory that may give more inspiration. A quick overview:

  • Search with EF Core and Sqlite.
  • User-friendly web interface, using Dapper and Postgres.
  • Generate SQL statements to create configurable tables (DDL)

Back to the concrete example of we can create a simple console app that allows you to search CBE data locally:

1. Get the data

Create an account on the official CBE website. With username/password you can download the public open data. 1️⃣

2. Configure

After installing the packages,

dotnet add package Vivarni.CBE
dotnet add package Vivarni.CBE.SqlServer # if you're using SQL Server
dotnet add package Vivarni.CBE.Postgres  # if you're using Postgres
dotnet add package Vivarni.CBE.Sqlite    # if you're using Sqlite
dotnet add package Vivarni.CBE.Oracle    # if you're using Oracle

add your configuration to your IServiceCollection. Adjust connection string, schema, and source for your environment. You can then

using Microsoft.Data.Sqlite;
using Microsoft.Extensions.DependencyInjection;
using Vivarni.CBE;
using Vivarni.CBE.Sqlite;

// Configure Vivarni.CBE with the desired source or data store.
// You can easily create your own data store for more control!
var connectionString = "Data Source=c:/kbo.db";
var services = new ServiceCollection()
    .AddVivarniCBE(s => s
        .WithFtps("cbe-username", "MySecret") 1️⃣
        .WithCache("c:/temp/") 2️⃣
        .WithSqliteDatabase(connectionString) 3️⃣
    );

4. Import/sync

Then run a sync for the first time to trigger an import of your data. The method can be called anytime and will attempt to update to the latest version of CBE data. It will use partial updates when possible and use ICbeSynchronisationStateRegistry to keep track of the synchronisation state. The CBE publishes partial update files on a daily basis.

var provider = services.BuildServiceProvider();
var cbeService = provider.GetRequiredService<ICbeService>();
await cbeService.SyncAsync();

5. Query 4️⃣

using Dapper;

using var connection = new SqliteConnection(connectionString);
await connection.OpenAsync();

var companies = await connection.QueryAsync<(string Vat, string Name)>(
    "SELECT vat_number AS Vat, name AS Name FROM cbe_companies WHERE name LIKE @q",
    new { q = "%TECH%" }
);

foreach (var row in companies)
{
    Console.WriteLine($"{row.Vat} - {row.Name}");
}

License

This project is licensed under the MIT License. Feel free to use it in your projects.

About

A simple solution for importing and synchronizing CBE data into Oracle, Postgres, SQL Server, or any other database. CBE is the English acronym for Kruispuntbank van Ondernemingen (KBO) or Banque-Carrefour des Entreprises (BCE).

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages