/// <summary>
 /// For __RepoDb_OrderColumn
 /// </summary>
 /// <param name="importer"></param>
 /// <param name="identityBehavior"></param>
 /// <param name="index"></param>
 /// <param name="cancellationToken"></param>
 private static async Task EnsureCustomizedOrderColumnAsync(NpgsqlBinaryImporter importer,
                                                            BulkImportIdentityBehavior identityBehavior,
                                                            int index,
                                                            CancellationToken cancellationToken = default)
 {
     if (identityBehavior == BulkImportIdentityBehavior.ReturnIdentity)
     {
         await importer.WriteAsync(index, NpgsqlDbType.Integer, cancellationToken);
     }
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="importer"></param>
 /// <param name="data"></param>
 /// <param name="npgsqlDbType"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 private static async Task BinaryImportWriteAsync(NpgsqlBinaryImporter importer,
                                                  object data,
                                                  NpgsqlDbType?npgsqlDbType,
                                                  CancellationToken cancellationToken = default)
 {
     if (data == null)
     {
         await importer.WriteNullAsync(cancellationToken);
     }
     else
     {
         if (npgsqlDbType != null)
         {
             await importer.WriteAsync(data, npgsqlDbType.Value, cancellationToken);
         }
         else
         {
             await importer.WriteAsync(data, cancellationToken);
         }
     }
 }
예제 #3
0
        public static async Task PerformBulkCopyAsync(this DbDataReader dr, NpgsqlBinaryImporter writer, DataColumnCollection columns = null)
        {
            columns ??= dr.GetSchemaTable().Columns;

            while (await dr.ReadAsync())
            {
                await writer.StartRowAsync();

                foreach (DataColumn col in columns)
                {
                    switch (dr[col.Ordinal])
                    {
                    case bool x:
                        await writer.WriteAsync(x);

                        break;

                    case byte x:
                        await writer.WriteAsync(x);

                        break;

                    case sbyte x:
                        await writer.WriteAsync(x);

                        break;

                    case short x:
                        await writer.WriteAsync(x);

                        break;

                    case ushort x:
                        await writer.WriteAsync(x);

                        break;

                    case int x:
                        await writer.WriteAsync(x);

                        break;

                    case uint x:
                        await writer.WriteAsync(x);

                        break;

                    case long x:
                        await writer.WriteAsync(x);

                        break;

                    case ulong x:
                        await writer.WriteAsync(x);

                        break;

                    case Guid x:
                        await writer.WriteAsync(x);

                        break;

                    case DateTime x:
                        await writer.WriteAsync(x);

                        break;

                    case TimeSpan x:
                        await writer.WriteAsync(x);

                        break;

                    case string x:
                        await writer.WriteAsync(x);

                        break;

                    case null:
                        writer.WriteNull();
                        break;
                    }
                }
            }

            await writer.CompleteAsync();
        }