Skip to content

Commit

Permalink
Break down native methods in separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi committed Sep 13, 2023
1 parent 4ff6ae2 commit 17747a5
Show file tree
Hide file tree
Showing 13 changed files with 522 additions and 450 deletions.
450 changes: 0 additions & 450 deletions DuckDB.NET.Bindings/NativeMethods.cs

This file was deleted.

8 changes: 8 additions & 0 deletions DuckDB.NET.Bindings/NativeMethods/NativeMethods.All.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace DuckDB.NET;

public static partial class NativeMethods
{
private const string DuckDbLibrary = "duckdb";

//Grouped according to https://duckdb.org/docs/archive/0.8.1/api/c/api
}
136 changes: 136 additions & 0 deletions DuckDB.NET.Bindings/NativeMethods/NativeMethods.Appender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using System.Runtime.InteropServices;

namespace DuckDB.NET;

public partial class NativeMethods
{
public static class Appender
{
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_appender_create")]
public static extern DuckDBState DuckDBAppenderCreate(DuckDBNativeConnection connection, string schema, string table, out DuckDBAppender appender);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_appender_error")]
public static extern IntPtr DuckDBAppenderError(DuckDBAppender appender);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_appender_flush")]
public static extern DuckDBState DuckDBAppenderFlush(DuckDBAppender appender);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_appender_end_row")]
public static extern DuckDBState DuckDBAppenderEndRow(DuckDBAppender appender);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_appender_close")]
public static extern DuckDBState DuckDBAppenderClose(DuckDBAppender appender);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_appender_destroy")]
public static extern DuckDBState DuckDBDestroyAppender(out IntPtr appender);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_bool")]
public static extern DuckDBState DuckDBAppendBool(DuckDBAppender appender, bool val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_int8")]
public static extern DuckDBState DuckDBAppendInt8(DuckDBAppender appender, sbyte val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_int16")]
public static extern DuckDBState DuckDBAppendInt16(DuckDBAppender appender, short val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_int32")]
public static extern DuckDBState DuckDBAppendInt32(DuckDBAppender appender, int val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_int64")]
public static extern DuckDBState DuckDBAppendInt64(DuckDBAppender appender, long val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_hugeint")]
public static extern DuckDBState DuckDBAppendHugeInt(DuckDBAppender appender, DuckDBHugeInt val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_uint8")]
public static extern DuckDBState DuckDBAppendUInt8(DuckDBAppender appender, byte val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_uint16")]
public static extern DuckDBState DuckDBAppendUInt16(DuckDBAppender appender, ushort val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_uint32")]
public static extern DuckDBState DuckDBAppendUInt32(DuckDBAppender appender, uint val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_uint64")]
public static extern DuckDBState DuckDBAppendUInt64(DuckDBAppender appender, ulong val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_float")]
public static extern DuckDBState DuckDBAppendFloat(DuckDBAppender appender, float val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_double")]
public static extern DuckDBState DuckDBAppendDouble(DuckDBAppender appender, double val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_date")]
public static extern DuckDBState DuckDBAppendDate(DuckDBAppender appender, DuckDBDate val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_time")]
public static extern DuckDBState DuckDBAppendTime(DuckDBAppender appender, DuckDBTime val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_timestamp")]
public static extern DuckDBState DuckDBAppendTimestamp(DuckDBAppender appender, DuckDBTimestampStruct val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_interval")]
public static extern DuckDBState DuckDBAppendInterval(DuckDBAppender appender, DuckDBInterval val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_varchar")]
public static extern DuckDBState DuckDBAppendVarchar(DuckDBAppender appender, SafeUnmanagedMemoryHandle val);

#if NET5_0_OR_GREATER
[SuppressGCTransition]
#endif
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_append_null")]
public static extern DuckDBState DuckDBAppendNull(DuckDBAppender appender);
}
}
25 changes: 25 additions & 0 deletions DuckDB.NET.Bindings/NativeMethods/NativeMethods.Configure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Runtime.InteropServices;

namespace DuckDB.NET;

public partial class NativeMethods
{
public static class Configure
{
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_create_config")]
public static extern DuckDBState DuckDBCreateConfig(out DuckDBConfig config);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_config_count")]
public static extern int DuckDBConfigCount();

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_get_config_flag")]
public static extern DuckDBState DuckDBGetConfigFlag(int index, out IntPtr name, out IntPtr description);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_set_config")]
public static extern DuckDBState DuckDBSetConfig(DuckDBConfig config, string name, string option);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_destroy_config")]
public static extern void DuckDBDestroyConfig(out IntPtr config);
}
}
37 changes: 37 additions & 0 deletions DuckDB.NET.Bindings/NativeMethods/NativeMethods.DataChunks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Runtime.InteropServices;

namespace DuckDB.NET;

public partial class NativeMethods
{
public static class DataChunks
{
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_data_chunk_get_column_count")]
public static extern long DuckDBDataChunkGetColumnCount(IntPtr chunk);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_data_chunk_get_vector")]
public static extern IntPtr DuckDBDataChunkGetVector(IntPtr chunk, long columnIndex);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_data_chunk_get_size")]
public static extern long DuckDBDataChunkGetSize(IntPtr chunk);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_vector_get_column_type")]
public static extern IntPtr DuckDBVectorGetColumnType(IntPtr vector);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_vector_get_data")]
public static extern IntPtr DuckDBVectorGetData(IntPtr vector);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_vector_get_validity")]
public static extern IntPtr DuckDBVectorGetValidity(IntPtr vector);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_list_vector_get_child")]
public static extern long DuckDBListVectorGetChild(IntPtr vector);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_list_vector_get_size")]
public static extern long DuckDBListVectorGetSize(IntPtr vector);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_struct_vector_get_child")]
public static extern long DuckDBStructVectorGetChild(IntPtr vector, long index);
}
}
27 changes: 27 additions & 0 deletions DuckDB.NET.Bindings/NativeMethods/NativeMethods.DateTime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Runtime.InteropServices;

namespace DuckDB.NET;

public partial class NativeMethods
{
public static class DateTime
{
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_from_date")]
public static extern DuckDBDateOnly DuckDBFromDate(DuckDBDate date);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_to_date")]
public static extern DuckDBDate DuckDBToDate(DuckDBDateOnly dateStruct);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_from_time")]
public static extern DuckDBTimeOnly DuckDBFromTime(DuckDBTime date);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_to_time")]
public static extern DuckDBTime DuckDBToTime(DuckDBTimeOnly dateStruct);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_from_timestamp")]
public static extern DuckDBTimestamp DuckDBFromTimestamp(DuckDBTimestampStruct date);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_to_timestamp")]
public static extern DuckDBTimestampStruct DuckDBToTimestamp(DuckDBTimestamp dateStruct);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Runtime.InteropServices;

namespace DuckDB.NET;

public partial class NativeMethods
{
public static class ExtractStatements
{
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_extract_statements")]
public static extern int DuckDBExtractStatements(DuckDBNativeConnection connection, string query, out DuckDBExtractedStatements extractedStatements);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_prepare_extracted_statement")]
public static extern DuckDBState DuckDBPrepareExtractedStatement(DuckDBNativeConnection connection, DuckDBExtractedStatements extractedStatements, long index, out DuckDBPreparedStatement preparedStatement);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_extract_statements_error")]
public static extern IntPtr DuckDBExtractStatementsError(DuckDBExtractedStatements extractedStatements);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_destroy_extracted")]
public static extern void DuckDBDestroyExtracted(out IntPtr extractedStatements);
}
}
16 changes: 16 additions & 0 deletions DuckDB.NET.Bindings/NativeMethods/NativeMethods.Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Runtime.InteropServices;

namespace DuckDB.NET;

public partial class NativeMethods
{
public static class Helpers
{
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_free")]
public static extern void DuckDBFree(IntPtr ptr);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_decimal_to_double")]
public static extern double DuckDBDecimalToDouble(DuckDBDecimal val);
}
}
22 changes: 22 additions & 0 deletions DuckDB.NET.Bindings/NativeMethods/NativeMethods.LogicalType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Runtime.InteropServices;

namespace DuckDB.NET;

public partial class NativeMethods
{
public static class LogicalType
{
[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_decimal_width")]
public static extern byte DuckDBDecimalWidth(DuckDBLogicalType type);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_decimal_scale")]
public static extern byte DuckDBDecimalScale(DuckDBLogicalType type);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_decimal_internal_type")]
public static extern DuckDBType DuckDBDecimalInternalType(DuckDBLogicalType type);

[DllImport(DuckDbLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "duckdb_destroy_logical_type")]
public static extern void DuckDBDestroyLogicalType(out IntPtr type);
}
}
Loading

0 comments on commit 17747a5

Please sign in to comment.