[
  {
    "path": ".gitignore",
    "content": "# Compiled Object files, Static and Dynamic libs (Shared Objects)\n*.o\n*.a\n*.so\n\n# Folders\n_obj\n_test\n\n# Architecture specific extensions/prefixes\n*.[568vq]\n[568vq].out\n\n*.cgo1.go\n*.cgo2.c\n_cgo_defun.c\n_cgo_gotypes.go\n_cgo_export.*\n\n_testmain.go\n\n*.exe\n*.test\n*.prof\n.idea/\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: go\naddons:\n  mariadb: '10.3'\ngo:\n  - tip\nbefore_install:\n  - go get github.com/mattn/goveralls\n  - go get golang.org/x/tools/cmd/cover\n  - mysql < tests/mariadb.sql\nscript:\n  - $HOME/gopath/bin/goveralls -service=travis-ci\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    {one line to give the program's name and a brief idea of what it does.}\n    Copyright (C) {year}  {name of author}\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    {project}  Copyright (C) {year}  {fullname}\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "# db2struct [![Build Status](https://travis-ci.org/Shelnutt2/db2struct.svg?branch=master)](https://travis-ci.org/Shelnutt2/db2struct) [![Coverage Status](https://coveralls.io/repos/github/Shelnutt2/db2struct/badge.svg?branch=1-add-coveralls-support)](https://coveralls.io/github/Shelnutt2/db2struct?branch=1-add-coveralls-support) [![GoDoc](https://godoc.org/github.com/Shelnutt2/db2struct?status.svg)](https://godoc.org/github.com/Shelnutt2/db2struct)\n\nThe db2struct package produces a usable golang struct from a given database table for use in a .go file.\n\nBy reading details from the database about the column structure, db2struct generates a go compatible struct type\nwith the required column names, data types, and annotations.\n\nGenerated datatypes include support for nullable columns [sql.NullX types](https://golang.org/pkg/database/sql/#NullBool) or [guregu null.X types](https://github.com/guregu/null)\nand the expected basic built in go types.\n\nDb2Struct is based/inspired by the work of ChimeraCoder's gojson package\n[gojson](https://github.com/ChimeraCoder/gojson)\n\n\n\n## Usage\n\n```BASH\ngo get github.com/Shelnutt2/db2struct/cmd/db2struct\ndb2struct --host localhost -d test -t test_table --package myGoPackage --struct testTable -p --user testUser\n```\n\n## Example\n\nMySQL table named users with four columns: id (int), user_name (varchar(255)), number_of_logins (int(11),nullable), and LAST_NAME (varchar(255), nullable)  \n\nExample below uses guregu's null package, but without the option it procuded the sql.NullInt64 and so on.\n```BASH\ndb2struct --host localhost -d example.com -t users --package example --struct user -p --user exampleUser --guregu --gorm\n```\n\nOutput:\n```GOLANG\n\npackage example\n\ntype User struct {\n  ID              int   `gorm:\"column:id\"`\n  UserName        string `gorm:\"column:user_name\"`\n  NumberOfLogins  null.Int `gorm:\"column:number_of_logins\"`\n  LastName        null.String `gorm:\"column:LAST_NAME\"`\n}\n```\n\n## Supported Databases\n\nCurrently Supported\n-   MariaDB\n-   MySQL\n\nPlanned Support\n-   PostgreSQL\n-   Oracle\n-   Microsoft SQL Server\n\n### MariaDB/MySQL\n\nStructures are created by querying the INFORMATION_SCHEMA.Columns table and then formatting the types, column names,\nand metadata to create a usable go compatible struct type.\n\nNOTE: If you wish to use a unix socket instead of a TCP socket,\nspecify the hostname as `unix:` then the path to the named socket.\nFor example:\n\n```BASH\n--host unix:/tmp/mysql.sock\n```\n\n#### Supported Datatypes\n\nCurrently only a limited number of MariaDB/MySQL datatypes are supported. Initial support includes:\n-   tinyint (sql.NullInt64 or null.Int)\n-   int      (sql.NullInt64 or null.Int)\n-   smallint      (sql.NullInt64 or null.Int)\n-   mediumint      (sql.NullInt64 or null.Int)\n-   bigint (sql.NullInt64 or null.Int)\n-   decimal (sql.NullFloat64 or null.Float)\n-   float (sql.NullFloat64 or null.Float)\n-   double (sql.NullFloat64 or null.Float)\n-   datetime (null.Time)\n-   time  (null.Time)\n-   date (null.Time)\n-   timestamp (null.Time)\n-   var (sql.String or null.String)\n-   enum (sql.String or null.String)\n-   varchar (sql.String or null.String)\n-   longtext (sql.String or null.String)\n-   mediumtext (sql.String or null.String)\n-   text (sql.String or null.String)\n-   tinytext (sql.String or null.String)\n-   binary\n-   blob\n-   longblob\n-   mediumblob\n-   varbinary\n-   json\n"
  },
  {
    "path": "cmd/db2struct/main.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\n\t\"github.com/Shelnutt2/db2struct\"\n\tgoopt \"github.com/droundy/goopt\"\n\t_ \"github.com/go-sql-driver/mysql\"\n\t\"github.com/howeyc/gopass\"\n)\n\nvar mariadbHost = os.Getenv(\"MYSQL_HOST\")\nvar mariadbHostPassed = goopt.String([]string{\"-H\", \"--host\"}, \"\", \"Host to check mariadb status of\")\nvar mariadbPort = goopt.Int([]string{\"--mysql_port\"}, 3306, \"Specify a port to connect to\")\nvar mariadbTable = goopt.String([]string{\"-t\", \"--table\"}, \"\", \"Table to build struct from\")\nvar mariadbDatabase = goopt.String([]string{\"-d\", \"--database\"}, \"nil\", \"Database to for connection\")\nvar mariadbPassword *string\nvar mariadbUser = goopt.String([]string{\"-u\", \"--user\"}, \"user\", \"user to connect to database\")\nvar verbose = goopt.Flag([]string{\"-v\", \"--verbose\"}, []string{}, \"Enable verbose output\", \"\")\nvar packageName = goopt.String([]string{\"--package\"}, \"\", \"name to set for package\")\nvar structName = goopt.String([]string{\"--struct\"}, \"\", \"name to set for struct\")\n\nvar jsonAnnotation = goopt.Flag([]string{\"--json\"}, []string{\"--no-json\"}, \"Add json annotations (default)\", \"Disable json annotations\")\nvar gormAnnotation = goopt.Flag([]string{\"--gorm\"}, []string{}, \"Add gorm annotations (tags)\", \"\")\nvar gureguTypes = goopt.Flag([]string{\"--guregu\"}, []string{}, \"Add guregu null types\", \"\")\nvar targetFile = goopt.String([]string{\"--target\"}, \"\", \"Save file path\")\n\nfunc init() {\n\tgoopt.OptArg([]string{\"-p\", \"--password\"}, \"\", \"Mysql password\", getMariadbPassword)\n\t//goopt.ReqArg([]string{\"-u\", \"--user\"}, \"user\", \"user to connect to database\", setUser)\n\n\t// Setup goopts\n\tgoopt.Description = func() string {\n\t\treturn \"Mariadb http Check\"\n\t}\n\tgoopt.Version = \"0.0.2\"\n\tgoopt.Summary = \"db2struct [-H] [-p] [-v] --package pkgName --struct structName --database databaseName --table tableName\"\n\n\t//Parse options\n\tgoopt.Parse(nil)\n\n}\n\nfunc main() {\n\n\t// Username is required\n\tif mariadbUser == nil || *mariadbUser == \"user\" {\n\t\tfmt.Println(\"Username is required! Add it with --user=name\")\n\t\treturn\n\t}\n\n\t// If a mariadb host is passed use it\n\tif mariadbHostPassed != nil && *mariadbHostPassed != \"\" {\n\t\tmariadbHost = *mariadbHostPassed\n\t}\n\n\tif mariadbPassword != nil && *mariadbPassword == \"\" {\n\t\tfmt.Print(\"Password: \")\n\t\tpass, err := gopass.GetPasswd()\n\t\tstringPass := string(pass)\n\t\tmariadbPassword = &stringPass\n\t\tif err != nil {\n\t\t\tfmt.Println(\"Error reading password: \" + err.Error())\n\t\t\treturn\n\t\t}\n\t} else if mariadbPassword == nil {\n\t\tp := \"\"\n\t\tmariadbPassword = &p\n\t}\n\n\tif *verbose {\n\t\tfmt.Println(\"Connecting to mysql server \" + mariadbHost + \":\" + strconv.Itoa(*mariadbPort))\n\t}\n\n\tif mariadbDatabase == nil || *mariadbDatabase == \"\" {\n\t\tfmt.Println(\"Database can not be null\")\n\t\treturn\n\t}\n\n\tif mariadbTable == nil || *mariadbTable == \"\" {\n\t\tfmt.Println(\"Table can not be null\")\n\t\treturn\n\t}\n\n\tcolumnDataTypes, columnsSorted, err := db2struct.GetColumnsFromMysqlTable(*mariadbUser, *mariadbPassword, mariadbHost, *mariadbPort, *mariadbDatabase, *mariadbTable)\n\n\tif err != nil {\n\t\tfmt.Println(\"Error in selecting column data information from mysql information schema\")\n\t\treturn\n\t}\n\n\t// If structName is not set we need to default it\n\tif structName == nil || *structName == \"\" {\n\t\t*structName = \"newstruct\"\n\t}\n\t// If packageName is not set we need to default it\n\tif packageName == nil || *packageName == \"\" {\n\t\t*packageName = \"newpackage\"\n\t}\n\t// Generate struct string based on columnDataTypes\n\tstruc, err := db2struct.Generate(*columnDataTypes, columnsSorted, *mariadbTable, *structName, *packageName, *jsonAnnotation, *gormAnnotation, *gureguTypes)\n\n\tif err != nil {\n\t\tfmt.Println(\"Error in creating struct from json: \" + err.Error())\n\t\treturn\n\t}\n\tif targetFile != nil && *targetFile != \"\" {\n\t\tfile, err := os.OpenFile(*targetFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)\n\t\tif err != nil {\n\t\t\tfmt.Println(\"Open File fail: \" + err.Error())\n\t\t\treturn\n\t\t}\n\t\tlength, err := file.WriteString(string(struc))\n\t\tif err != nil {\n\t\t\tfmt.Println(\"Save File fail: \" + err.Error())\n\t\t\treturn\n\t\t}\n\t\tfmt.Printf(\"wrote %d bytes\\n\", length)\n\t} else {\n\t\tfmt.Println(string(struc))\n\t}\n}\n\nfunc getMariadbPassword(password string) error {\n\tmariadbPassword = new(string)\n\t*mariadbPassword = password\n\treturn nil\n}\n"
  },
  {
    "path": "go.mod",
    "content": "module github.com/Shelnutt2/db2struct\n\ngo 1.12\n\nrequire (\n\tgithub.com/droundy/goopt v0.0.0-20170604162106-0b8effe182da\n\tgithub.com/go-sql-driver/mysql v1.4.1\n\tgithub.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c\n\tgithub.com/smartystreets/goconvey v1.7.2\n\tgolang.org/x/crypto v0.1.0 // indirect\n\tgoogle.golang.org/appengine v1.6.7 // indirect\n)\n"
  },
  {
    "path": "go.sum",
    "content": "github.com/droundy/goopt v0.0.0-20170604162106-0b8effe182da h1:79H+mNJWOObWrQgbkSvvZ3t/D2lKWaTi9mu/v7fNRvg=\ngithub.com/droundy/goopt v0.0.0-20170604162106-0b8effe182da/go.mod h1:ytRJ64WkuW4kf6/tuYqBATBCRFUP8X9+LDtgcvE+koI=\ngithub.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=\ngithub.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=\ngithub.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=\ngithub.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=\ngithub.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=\ngithub.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c h1:kQWxfPIHVLbgLzphqk3QUflDy9QdksZR4ygR807bpy0=\ngithub.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs=\ngithub.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=\ngithub.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=\ngithub.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=\ngithub.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=\ngithub.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=\ngithub.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=\ngithub.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=\ngolang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=\ngolang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=\ngolang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=\ngolang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=\ngolang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=\ngolang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=\ngolang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=\ngolang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=\ngolang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=\ngolang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=\ngolang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=\ngolang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\ngolang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=\ngolang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=\ngolang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=\ngolang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw=\ngolang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=\ngolang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=\ngolang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=\ngolang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=\ngolang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=\ngolang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=\ngolang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=\ngolang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=\ngolang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=\ngolang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=\ngolang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=\ngoogle.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=\ngoogle.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=\n"
  },
  {
    "path": "tests/mariadb.sql",
    "content": "CREATE DATABASE IF NOT EXISTS test;\nDROP TABLE IF EXISTS test.`all_data_types`;\nCREATE TABLE test.`all_data_types` (\n`varchar` VARCHAR( 20 ) NOT NULL ,\n`tinyint` TINYINT NOT NULL ,\n`text` TEXT NOT NULL ,\n`date` DATE NOT NULL ,\n`smallint` SMALLINT NOT NULL ,\n`mediumint` MEDIUMINT NOT NULL ,\n`int` INT NOT NULL ,\n`bigint` BIGINT NOT NULL ,\n`float` FLOAT( 10, 2 ) NOT NULL ,\n`double` DOUBLE NOT NULL ,\n`decimal` DECIMAL( 10, 2 ) NOT NULL ,\n`datetime` DATETIME NOT NULL ,\n`timestamp` TIMESTAMP NOT NULL ,\n`time` TIME NOT NULL ,\n`year` YEAR NOT NULL ,\n`char` CHAR( 10 ) NOT NULL ,\n`tinyblob` TINYBLOB NOT NULL ,\n`tinytext` TINYTEXT NOT NULL ,\n`blob` BLOB NOT NULL ,\n`mediumblob` MEDIUMBLOB NOT NULL ,\n`mediumtext` MEDIUMTEXT NOT NULL ,\n`longblob` LONGBLOB NOT NULL ,\n`longtext` LONGTEXT NOT NULL ,\n`enum` ENUM( '1', '2', '3' ) NOT NULL ,\n`set` SET( '1', '2', '3' ) NOT NULL ,\n`bool` BOOL NOT NULL ,\n`binary` BINARY( 20 ) NOT NULL ,\n`varbinary` VARBINARY( 20 ) NOT NULL\n);\n"
  },
  {
    "path": "utils.go",
    "content": "package db2struct\n\nimport (\n\t\"fmt\"\n\t\"go/format\"\n\t\"strconv\"\n\t\"strings\"\n\t\"unicode\"\n)\n\n// Constants for return types of golang\nconst (\n\tgolangByteArray  = \"[]byte\"\n\tgureguNullInt    = \"null.Int\"\n\tsqlNullInt       = \"sql.NullInt64\"\n\tgolangInt        = \"int\"\n\tgolangInt64      = \"int64\"\n\tgureguNullFloat  = \"null.Float\"\n\tsqlNullFloat     = \"sql.NullFloat64\"\n\tgolangFloat      = \"float\"\n\tgolangFloat32    = \"float32\"\n\tgolangFloat64    = \"float64\"\n\tgureguNullString = \"null.String\"\n\tsqlNullString    = \"sql.NullString\"\n\tgureguNullTime   = \"null.Time\"\n\tgolangTime       = \"time.Time\"\n)\n\n// commonInitialisms is a set of common initialisms.\n// Only add entries that are highly unlikely to be non-initialisms.\n// For instance, \"ID\" is fine (Freudian code is rare), but \"AND\" is not.\nvar commonInitialisms = map[string]bool{\n\t\"API\":   true,\n\t\"ASCII\": true,\n\t\"CPU\":   true,\n\t\"CSS\":   true,\n\t\"DNS\":   true,\n\t\"EOF\":   true,\n\t\"GUID\":  true,\n\t\"HTML\":  true,\n\t\"HTTP\":  true,\n\t\"HTTPS\": true,\n\t\"ID\":    true,\n\t\"IP\":    true,\n\t\"JSON\":  true,\n\t\"LHS\":   true,\n\t\"QPS\":   true,\n\t\"RAM\":   true,\n\t\"RHS\":   true,\n\t\"RPC\":   true,\n\t\"SLA\":   true,\n\t\"SMTP\":  true,\n\t\"SSH\":   true,\n\t\"TLS\":   true,\n\t\"TTL\":   true,\n\t\"UI\":    true,\n\t\"UID\":   true,\n\t\"UUID\":  true,\n\t\"URI\":   true,\n\t\"URL\":   true,\n\t\"UTF8\":  true,\n\t\"VM\":    true,\n\t\"XML\":   true,\n}\n\nvar intToWordMap = []string{\n\t\"zero\",\n\t\"one\",\n\t\"two\",\n\t\"three\",\n\t\"four\",\n\t\"five\",\n\t\"six\",\n\t\"seven\",\n\t\"eight\",\n\t\"nine\",\n}\n\n//Debug level logging\nvar Debug = false\n\n// Generate Given a Column map with datatypes and a name structName,\n// attempts to generate a struct definition\nfunc Generate(columnTypes map[string]map[string]string, columnsSorted []string, tableName string, structName string, pkgName string, jsonAnnotation bool, gormAnnotation bool, gureguTypes bool) ([]byte, error) {\n\tvar dbTypes string\n\tdbTypes = generateMysqlTypes(columnTypes, columnsSorted, 0, jsonAnnotation, gormAnnotation, gureguTypes)\n\tsrc := fmt.Sprintf(\"package %s\\ntype %s %s\\n}\",\n\t\tpkgName,\n\t\tstructName,\n\t\tdbTypes)\n\tif gormAnnotation == true {\n\t\ttableNameFunc := \"// TableName sets the insert table name for this struct type\\n\" +\n\t\t\t\"func (\" + strings.ToLower(string(structName[0])) + \" *\" + structName + \") TableName() string {\\n\" +\n\t\t\t\"\treturn \\\"\" + tableName + \"\\\"\" +\n\t\t\t\"}\"\n\t\tsrc = fmt.Sprintf(\"%s\\n%s\", src, tableNameFunc)\n\t}\n\tformatted, err := format.Source([]byte(src))\n\tif err != nil {\n\t\terr = fmt.Errorf(\"error formatting: %s, was formatting\\n%s\", err, src)\n\t}\n\treturn formatted, err\n}\n\n// fmtFieldName formats a string as a struct key\n//\n// Example:\n// \tfmtFieldName(\"foo_id\")\n// Output: FooID\nfunc fmtFieldName(s string) string {\n\tname := lintFieldName(s)\n\trunes := []rune(name)\n\tfor i, c := range runes {\n\t\tok := unicode.IsLetter(c) || unicode.IsDigit(c)\n\t\tif i == 0 {\n\t\t\tok = unicode.IsLetter(c)\n\t\t}\n\t\tif !ok {\n\t\t\trunes[i] = '_'\n\t\t}\n\t}\n\treturn string(runes)\n}\n\nfunc lintFieldName(name string) string {\n\t// Fast path for simple cases: \"_\" and all lowercase.\n\tif name == \"_\" {\n\t\treturn name\n\t}\n\n\tfor len(name) > 0 && name[0] == '_' {\n\t\tname = name[1:]\n\t}\n\n\tallLower := true\n\tfor _, r := range name {\n\t\tif !unicode.IsLower(r) {\n\t\t\tallLower = false\n\t\t\tbreak\n\t\t}\n\t}\n\tif allLower {\n\t\trunes := []rune(name)\n\t\tif u := strings.ToUpper(name); commonInitialisms[u] {\n\t\t\tcopy(runes[0:], []rune(u))\n\t\t} else {\n\t\t\trunes[0] = unicode.ToUpper(runes[0])\n\t\t}\n\t\treturn string(runes)\n\t}\n\n\t// Split camelCase at any lower->upper transition, and split on underscores.\n\t// Check each word for common initialisms.\n\trunes := []rune(name)\n\tw, i := 0, 0 // index of start of word, scan\n\tfor i+1 <= len(runes) {\n\t\teow := false // whether we hit the end of a word\n\n\t\tif i+1 == len(runes) {\n\t\t\teow = true\n\t\t} else if runes[i+1] == '_' {\n\t\t\t// underscore; shift the remainder forward over any run of underscores\n\t\t\teow = true\n\t\t\tn := 1\n\t\t\tfor i+n+1 < len(runes) && runes[i+n+1] == '_' {\n\t\t\t\tn++\n\t\t\t}\n\n\t\t\t// Leave at most one underscore if the underscore is between two digits\n\t\t\tif i+n+1 < len(runes) && unicode.IsDigit(runes[i]) && unicode.IsDigit(runes[i+n+1]) {\n\t\t\t\tn--\n\t\t\t}\n\n\t\t\tcopy(runes[i+1:], runes[i+n+1:])\n\t\t\trunes = runes[:len(runes)-n]\n\t\t} else if unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]) {\n\t\t\t// lower->non-lower\n\t\t\teow = true\n\t\t}\n\t\ti++\n\t\tif !eow {\n\t\t\tcontinue\n\t\t}\n\n\t\t// [w,i) is a word.\n\t\tword := string(runes[w:i])\n\t\tif u := strings.ToUpper(word); commonInitialisms[u] {\n\t\t\t// All the common initialisms are ASCII,\n\t\t\t// so we can replace the bytes exactly.\n\t\t\tcopy(runes[w:], []rune(u))\n\n\t\t} else if strings.ToLower(word) == word {\n\t\t\t// already all lowercase, and not the first word, so uppercase the first character.\n\t\t\trunes[w] = unicode.ToUpper(runes[w])\n\t\t}\n\t\tw = i\n\t}\n\treturn string(runes)\n}\n\n// convert first character ints to strings\nfunc stringifyFirstChar(str string) string {\n\tfirst := str[:1]\n\n\ti, err := strconv.ParseInt(first, 10, 8)\n\n\tif err != nil {\n\t\treturn str\n\t}\n\n\treturn intToWordMap[i] + \"_\" + str[1:]\n}\n"
  },
  {
    "path": "utils_mysql.go",
    "content": "package db2struct\n\nimport (\n\t\"database/sql\"\n\t\"errors\"\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\n// GetColumnsFromMysqlTable Select column details from information schema and return map of map\nfunc GetColumnsFromMysqlTable(mariadbUser string, mariadbPassword string, mariadbHost string, mariadbPort int, mariadbDatabase string, mariadbTable string) (*map[string]map[string]string, []string, error) {\n\n\tvar err error\n\tvar db *sql.DB\n\tif strings.HasPrefix(mariadbHost, \"unix:\") {\n\t\tparts := strings.SplitN(mariadbHost, \":\", 2)\n\t\tsocketPath := parts[1]\n\t\tdb, err = sql.Open(\"mysql\", mariadbUser+\":\"+mariadbPassword+\"@unix(\"+socketPath+\")\"+\"/\"+mariadbDatabase+\"?charset=utf8&parseTime=True\")\n\t\t// Cite: https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-connection-socket.html\n\t\t// Cite: https://stackoverflow.com/a/67867865/71978\n\t} else {\n\t\tif mariadbPassword != \"\" {\n\t\t\tdb, err = sql.Open(\"mysql\", mariadbUser+\":\"+mariadbPassword+\"@tcp(\"+mariadbHost+\":\"+strconv.Itoa(mariadbPort)+\")/\"+mariadbDatabase+\"?&parseTime=True\")\n\t\t} else {\n\t\t\tdb, err = sql.Open(\"mysql\", mariadbUser+\"@tcp(\"+mariadbHost+\":\"+strconv.Itoa(mariadbPort)+\")/\"+mariadbDatabase+\"?&parseTime=True\")\n\t\t}\n\t}\n\tdefer db.Close()\n\n\t// Check for error in db, note this does not check connectivity but does check uri\n\tif err != nil {\n\t\tfmt.Println(\"Error opening mysql db: \" + err.Error())\n\t\treturn nil, nil, err\n\t}\n\n\tcolumnNamesSorted := []string{}\n\n\t// Store colum as map of maps\n\tcolumnDataTypes := make(map[string]map[string]string)\n\t// Select columnd data from INFORMATION_SCHEMA\n\tcolumnDataTypeQuery := \"SELECT COLUMN_NAME, COLUMN_KEY, DATA_TYPE, IS_NULLABLE, COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ? AND table_name = ? order by ordinal_position asc\"\n\n\tif Debug {\n\t\tfmt.Println(\"running: \" + columnDataTypeQuery)\n\t}\n\n\trows, err := db.Query(columnDataTypeQuery, mariadbDatabase, mariadbTable)\n\n\tif err != nil {\n\t\tfmt.Println(\"Error selecting from db: \" + err.Error())\n\t\treturn nil, nil, err\n\t}\n\tif rows != nil {\n\t\tdefer rows.Close()\n\t} else {\n\t\treturn nil, nil, errors.New(\"No results returned for table\")\n\t}\n\n\tfor rows.Next() {\n\t\tvar column string\n\t\tvar columnKey string\n\t\tvar dataType string\n\t\tvar nullable string\n\t\tvar comment string\n\t\trows.Scan(&column, &columnKey, &dataType, &nullable, &comment)\n\n\t\tcolumnDataTypes[column] = map[string]string{\"value\": dataType, \"nullable\": nullable, \"primary\": columnKey, \"comment\": comment}\n\t\tcolumnNamesSorted = append(columnNamesSorted, column)\n\t}\n\n\treturn &columnDataTypes, columnNamesSorted, err\n}\n\n// Generate go struct entries for a map[string]interface{} structure\nfunc generateMysqlTypes(obj map[string]map[string]string, columnsSorted []string, depth int, jsonAnnotation bool, gormAnnotation bool, gureguTypes bool) string {\n\tstructure := \"struct {\"\n\n\tfor _, key := range columnsSorted {\n\t\tmysqlType := obj[key]\n\t\tnullable := false\n\t\tif mysqlType[\"nullable\"] == \"YES\" {\n\t\t\tnullable = true\n\t\t}\n\n\t\tprimary := \"\"\n\t\tif mysqlType[\"primary\"] == \"PRI\" {\n\t\t\tprimary = \";primary_key\"\n\t\t}\n\n\t\t// Get the corresponding go value type for this mysql type\n\t\tvar valueType string\n\t\t// If the guregu (https://github.com/guregu/null) CLI option is passed use its types, otherwise use go's sql.NullX\n\n\t\tvalueType = mysqlTypeToGoType(mysqlType[\"value\"], nullable, gureguTypes)\n\n\t\tfieldName := fmtFieldName(stringifyFirstChar(key))\n\t\tvar annotations []string\n\t\tif gormAnnotation == true {\n\t\t\tannotations = append(annotations, fmt.Sprintf(\"gorm:\\\"column:%s%s\\\"\", key, primary))\n\t\t}\n\t\tif jsonAnnotation == true {\n\t\t\tannotations = append(annotations, fmt.Sprintf(\"json:\\\"%s\\\"\", key))\n\t\t}\n\n\t\tif len(annotations) > 0 {\n\t\t\t// add colulmn comment\n\t\t\tcomment := mysqlType[\"comment\"]\n\t\t\tstructure += fmt.Sprintf(\"\\n%s %s `%s`  //%s\", fieldName, valueType, strings.Join(annotations, \" \"), comment)\n\t\t\t//structure += fmt.Sprintf(\"\\n%s %s `%s`\", fieldName, valueType, strings.Join(annotations, \" \"))\n\t\t} else {\n\t\t\tstructure += fmt.Sprintf(\"\\n%s %s\", fieldName, valueType)\n\t\t}\n\t}\n\treturn structure\n}\n\n// mysqlTypeToGoType converts the mysql types to go compatible sql.Nullable (https://golang.org/pkg/database/sql/) types\nfunc mysqlTypeToGoType(mysqlType string, nullable bool, gureguTypes bool) string {\n\tswitch mysqlType {\n\tcase \"tinyint\", \"int\", \"smallint\", \"mediumint\":\n\t\tif nullable {\n\t\t\tif gureguTypes {\n\t\t\t\treturn gureguNullInt\n\t\t\t}\n\t\t\treturn sqlNullInt\n\t\t}\n\t\treturn golangInt\n\tcase \"bigint\":\n\t\tif nullable {\n\t\t\tif gureguTypes {\n\t\t\t\treturn gureguNullInt\n\t\t\t}\n\t\t\treturn sqlNullInt\n\t\t}\n\t\treturn golangInt64\n\tcase \"char\", \"enum\", \"varchar\", \"longtext\", \"mediumtext\", \"text\", \"tinytext\", \"json\":\n\t\tif nullable {\n\t\t\tif gureguTypes {\n\t\t\t\treturn gureguNullString\n\t\t\t}\n\t\t\treturn sqlNullString\n\t\t}\n\t\treturn \"string\"\n\tcase \"date\", \"datetime\", \"time\", \"timestamp\":\n\t\tif nullable && gureguTypes {\n\t\t\treturn gureguNullTime\n\t\t}\n\t\treturn golangTime\n\tcase \"decimal\", \"double\":\n\t\tif nullable {\n\t\t\tif gureguTypes {\n\t\t\t\treturn gureguNullFloat\n\t\t\t}\n\t\t\treturn sqlNullFloat\n\t\t}\n\t\treturn golangFloat64\n\tcase \"float\":\n\t\tif nullable {\n\t\t\tif gureguTypes {\n\t\t\t\treturn gureguNullFloat\n\t\t\t}\n\t\t\treturn sqlNullFloat\n\t\t}\n\t\treturn golangFloat32\n\tcase \"binary\", \"blob\", \"longblob\", \"mediumblob\", \"varbinary\":\n\t\treturn golangByteArray\n\t}\n\treturn \"\"\n}\n"
  },
  {
    "path": "utils_mysql_test.go",
    "content": "package db2struct\n\nimport (\n\t\"testing\"\n\n\t_ \"github.com/go-sql-driver/mysql\" // Initialize mysql driver\n\t. \"github.com/smartystreets/goconvey/convey\"\n)\n\nconst testMariadbUsername = \"root\"\nconst testMariadbPassword = \"\"\nconst testMariadbHost = \"127.0.0.1\"\nconst testMariadbPort = 3306\nconst testMariadbDatabase = \"test\"\n\nfunc TestGetColumnsFromMysqlTable(t *testing.T) {\n\tvar testTable = \"all_data_types\"\n\tcolumMap, err := GetColumnsFromMysqlTable(testMariadbUsername, testMariadbPassword, testMariadbHost, testMariadbPort, testMariadbDatabase, testTable)\n\tConvey(\"Should be able to connect to test database and create columnMap\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(columMap, ShouldNotBeNil)\n\t\tSo(*columMap, ShouldNotBeEmpty)\n\t})\n\n\tcolumMap, err = GetColumnsFromMysqlTable(testMariadbUsername, testMariadbPassword, \"doesnotexists\", testMariadbPort, testMariadbDatabase, testTable)\n\tConvey(\"Should get an error connecting to test database\", t, func() {\n\t\tSo(err, ShouldNotBeNil)\n\t\tSo(columMap, ShouldBeNil)\n\t})\n}\n"
  },
  {
    "path": "utils_test.go",
    "content": "package db2struct\n\nimport (\n\t\"testing\"\n\n\t. \"github.com/smartystreets/goconvey/convey\"\n)\n\nfunc TestLintFieldName(t *testing.T) {\n\tname := lintFieldName(\"_\")\n\tConvey(\"Should get underscore as fieldName\", t, func() {\n\t\tSo(name, ShouldEqual, \"_\")\n\t})\n\n\tname = lintFieldName(\"foo_id\")\n\tConvey(\"Should be able to convert field name\", t, func() {\n\t\tSo(name, ShouldEqual, \"FooID\")\n\t})\n\n\tname = lintFieldName(\"foo__id\")\n\tConvey(\"Should be able to convert field name\", t, func() {\n\t\tSo(name, ShouldEqual, \"FooID\")\n\t})\n\n\tname = lintFieldName(\"1__2\")\n\tConvey(\"Should be able to convert field name\", t, func() {\n\t\tSo(name, ShouldEqual, \"1_2\")\n\t})\n\n\tname = lintFieldName(\"_id\")\n\tConvey(\"Should be able to convert field name\", t, func() {\n\t\tSo(name, ShouldEqual, \"ID\")\n\t})\n\n\tname = lintFieldName(\"foo\")\n\tConvey(\"Should be able to convert field name\", t, func() {\n\t\tSo(name, ShouldEqual, \"Foo\")\n\t})\n}\n\nfunc TestMysqlStringGenerate(t *testing.T) {\n\texpectedStruct :=\n\t\t`package test\n\ntype testStruct struct {\n\tNullStringColumn sql.NullString\n\tStringColumn     string\n}\n`\n\n\tcolumnMap := map[string]map[string]string{\n\t\t\"stringColumn\":     {\"nullable\": \"NO\", \"value\": \"varchar\"},\n\t\t\"nullStringColumn\": {\"nullable\": \"YES\", \"value\": \"varchar\"},\n\t}\n\tbytes, err := Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, false, false)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n}\n\nfunc TestMysqlBlobGenerate(t *testing.T) {\n\texpectedStruct :=\n\t\t`package test\n\ntype testStruct struct {\n\tBinaryColumn         []byte\n\tBlobColumn           []byte\n\tLongBlobColumn       []byte\n\tMediumBlobColumn     []byte\n\tNullBinaryColumn     []byte\n\tNullBlobColumn       []byte\n\tNullLongBlobColumn   []byte\n\tNullMediumBlobColumn []byte\n\tNullVarbinaryColumn  []byte\n\tVarbinaryColumn      []byte\n}\n`\n\n\tcolumnMap := map[string]map[string]string{\n\t\t\"binaryColumn\":         {\"nullable\": \"NO\", \"value\": \"binary\"},\n\t\t\"nullBinaryColumn\":     {\"nullable\": \"YES\", \"value\": \"binary\"},\n\t\t\"blobColumn\":           {\"nullable\": \"NO\", \"value\": \"blob\"},\n\t\t\"nullBlobColumn\":       {\"nullable\": \"YES\", \"value\": \"blob\"},\n\t\t\"longBlobColumn\":       {\"nullable\": \"NO\", \"value\": \"longblob\"},\n\t\t\"nullLongBlobColumn\":   {\"nullable\": \"YES\", \"value\": \"longblob\"},\n\t\t\"mediumBlobColumn\":     {\"nullable\": \"NO\", \"value\": \"mediumblob\"},\n\t\t\"nullMediumBlobColumn\": {\"nullable\": \"YES\", \"value\": \"mediumblob\"},\n\t\t\"varbinaryColumn\":      {\"nullable\": \"NO\", \"value\": \"varbinary\"},\n\t\t\"nullVarbinaryColumn\":  {\"nullable\": \"YES\", \"value\": \"varbinary\"},\n\t}\n\tbytes, err := Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, false, false)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n}\n\nfunc TestMysqlDateGenerate(t *testing.T) {\n\tcolumnMap := map[string]map[string]string{\n\t\t\"DateColumn\":          {\"nullable\": \"NO\", \"value\": \"date\"},\n\t\t\"nullDateColumn\":      {\"nullable\": \"YES\", \"value\": \"date\"},\n\t\t\"DateTimeColumn\":      {\"nullable\": \"NO\", \"value\": \"datetime\"},\n\t\t\"nullDateTimeColumn\":  {\"nullable\": \"YES\", \"value\": \"datetime\"},\n\t\t\"TimeColumn\":          {\"nullable\": \"NO\", \"value\": \"time\"},\n\t\t\"nullTimeColumn\":      {\"nullable\": \"YES\", \"value\": \"time\"},\n\t\t\"TimeStampColumn\":     {\"nullable\": \"NO\", \"value\": \"timestamp\"},\n\t\t\"nullTimeStampColumn\": {\"nullable\": \"YES\", \"value\": \"timestamp\"},\n\t}\n\n\texpectedStruct :=\n\t\t`package test\n\ntype testStruct struct {\n\tDateColumn          time.Time\n\tDateTimeColumn      time.Time\n\tTimeColumn          time.Time\n\tTimeStampColumn     time.Time\n\tNullDateColumn      time.Time\n\tNullDateTimeColumn  time.Time\n\tNullTimeColumn      time.Time\n\tNullTimeStampColumn time.Time\n}\n`\n\n\tbytes, err := Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, false, false)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n\n\texpectedStruct =\n\t\t`package test\n\ntype testStruct struct {\n\tDateColumn          time.Time\n\tDateTimeColumn      time.Time\n\tTimeColumn          time.Time\n\tTimeStampColumn     time.Time\n\tNullDateColumn      null.Time\n\tNullDateTimeColumn  null.Time\n\tNullTimeColumn      null.Time\n\tNullTimeStampColumn null.Time\n}\n`\n\n\tbytes, err = Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, false, true)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n}\n\nfunc TestMysqlFloatGenerate(t *testing.T) {\n\n\tcolumnMap := map[string]map[string]string{\n\t\t\"floatColumn\":       {\"nullable\": \"NO\", \"value\": \"float\"},\n\t\t\"nullFloatColumn\":   {\"nullable\": \"YES\", \"value\": \"float\"},\n\t\t\"doubleColumn\":      {\"nullable\": \"NO\", \"value\": \"double\"},\n\t\t\"nullDoubleColumn\":  {\"nullable\": \"YES\", \"value\": \"double\"},\n\t\t\"decimalColumn\":     {\"nullable\": \"NO\", \"value\": \"decimal\"},\n\t\t\"nullDecimalColumn\": {\"nullable\": \"YES\", \"value\": \"decimal\"},\n\t}\n\n\texpectedStruct :=\n\t\t`package test\n\ntype testStruct struct {\n\tDecimalColumn     float64\n\tDoubleColumn      float64\n\tFloatColumn       float32\n\tNullDecimalColumn sql.NullFloat64\n\tNullDoubleColumn  sql.NullFloat64\n\tNullFloatColumn   sql.NullFloat64\n}\n`\n\n\tbytes, err := Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, false, false)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n\n\texpectedStruct =\n\t\t`package test\n\ntype testStruct struct {\n\tDecimalColumn     float64\n\tDoubleColumn      float64\n\tFloatColumn       float32\n\tNullDecimalColumn null.Float\n\tNullDoubleColumn  null.Float\n\tNullFloatColumn   null.Float\n}\n`\n\n\tbytes, err = Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, false, true)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n}\n\nfunc TestMysqlIntGenerate(t *testing.T) {\n\tcolumnMap := map[string]map[string]string{\n\t\t\"intColumn\":           {\"nullable\": \"NO\", \"value\": \"int\"},\n\t\t\"nullIntColumn\":       {\"nullable\": \"YES\", \"value\": \"int\"},\n\t\t\"tinyIntColumn\":       {\"nullable\": \"NO\", \"value\": \"tinyint\"},\n\t\t\"nullTinyIntColumn\":   {\"nullable\": \"YES\", \"value\": \"tinyint\"},\n\t\t\"smallIntColumn\":      {\"nullable\": \"NO\", \"value\": \"smallint\"},\n\t\t\"nullSmallIntColumn\":  {\"nullable\": \"YES\", \"value\": \"smallint\"},\n\t\t\"mediumIntColumn\":     {\"nullable\": \"NO\", \"value\": \"mediumint\"},\n\t\t\"nullMediumIntColumn\": {\"nullable\": \"YES\", \"value\": \"mediumint\"},\n\t\t\"bigIntColumn\":        {\"nullable\": \"NO\", \"value\": \"bigint\"},\n\t\t\"nullBigIntColumn\":    {\"nullable\": \"YES\", \"value\": \"bigint\"},\n\t}\n\n\texpectedStruct :=\n\t\t`package test\n\ntype testStruct struct {\n\tBigIntColumn        int64\n\tIntColumn           int\n\tMediumIntColumn     int\n\tNullBigIntColumn    sql.NullInt64\n\tNullIntColumn       sql.NullInt64\n\tNullMediumIntColumn sql.NullInt64\n\tNullSmallIntColumn  sql.NullInt64\n\tNullTinyIntColumn   sql.NullInt64\n\tSmallIntColumn      int\n\tTinyIntColumn       int\n}\n`\n\n\tbytes, err := Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, false, false)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n\n\texpectedStruct =\n\t\t`package test\n\ntype testStruct struct {\n\tBigIntColumn        int64\n\tIntColumn           int\n\tMediumIntColumn     int\n\tNullBigIntColumn    null.Int\n\tNullIntColumn       null.Int\n\tNullMediumIntColumn null.Int\n\tNullSmallIntColumn  null.Int\n\tNullTinyIntColumn   null.Int\n\tSmallIntColumn      int\n\tTinyIntColumn       int\n}\n`\n\n\tbytes, err = Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, false, true)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n}\n\nfunc TestMysqlJSONStringGenerate(t *testing.T) {\n\tcolumnMap := map[string]map[string]string{\n\t\t\"stringColumn\":     {\"nullable\": \"NO\", \"value\": \"varchar\"},\n\t\t\"nullStringColumn\": {\"nullable\": \"YES\", \"value\": \"varchar\"},\n\t}\n\n\texpectedStruct :=\n\t\t`package test\n\ntype testStruct struct {\n\tNullStringColumn sql.NullString ` + \"`json:\\\"nullStringColumn\\\"`\" + `\n\tStringColumn     string         ` + \"`json:\\\"stringColumn\\\"`\" + `\n}\n`\n\n\tbytes, err := Generate(columnMap, \"test_table\", \"testStruct\", \"test\", true, false, false)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n}\n\nfunc TestMysqlGormStringGenerate(t *testing.T) {\n\texpectedStruct :=\n\t\t`package test\n\ntype testStruct struct {\n\tNullStringColumn sql.NullString ` + \"`gorm:\\\"column:nullStringColumn\\\"`\" + `\n\tStringColumn     string         ` + \"`gorm:\\\"column:stringColumn\\\"`\" + `\n}\n\n// TableName sets the insert table name for this struct type\nfunc (t *testStruct) TableName() string {\n\treturn \"test_table\"\n}\n`\n\n\tcolumnMap := map[string]map[string]string{\n\t\t\"stringColumn\":     {\"nullable\": \"NO\", \"value\": \"varchar\"},\n\t\t\"nullStringColumn\": {\"nullable\": \"YES\", \"value\": \"varchar\"},\n\t}\n\tbytes, err := Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, true, false)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n}\n\nfunc TestMysqlStringWithIntGenerate(t *testing.T) {\n\texpectedStruct :=\n\t\t`package test\n\ntype testStruct struct {\n\tOneStringColumn string\n}\n`\n\n\tcolumnMap := map[string]map[string]string{\n\t\t\"1stringColumn\": {\"nullable\": \"NO\", \"value\": \"varchar\"},\n\t}\n\tbytes, err := Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, false, false)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n}\n\nfunc TestMysqlStringWithUnderscoresGenerate(t *testing.T) {\n\texpectedStruct :=\n\t\t`package test\n\ntype testStruct struct {\n\tStringColumn string\n}\n`\n\n\tcolumnMap := map[string]map[string]string{\n\t\t\"string_Column\": {\"nullable\": \"NO\", \"value\": \"varchar\"},\n\t}\n\tbytes, err := Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, false, false)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n}\n\nfunc TestMysqlStringWithCommonInitialismGenerate(t *testing.T) {\n\texpectedStruct :=\n\t\t`package test\n\ntype testStruct struct {\n\tAPI string\n}\n`\n\n\tcolumnMap := map[string]map[string]string{\n\t\t\"API\": {\"nullable\": \"NO\", \"value\": \"varchar\"},\n\t}\n\tbytes, err := Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, false, false)\n\n\tConvey(\"Should be able to generate map from string column\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n}\n\n// TestMysqlTypeToGureguType generates the struct and outputs nullable columns as guregu null types\nfunc TestMysqlTypeToGureguType(t *testing.T) {\n\texpectedStruct :=\n\t\t`package test\n\ntype testStruct struct {\n\tBigInt    int64\n\tDate      null.Time\n\tDateTime  null.Time\n\tDecimal   null.Float\n\tDouble    float64\n\tFloat     null.Float\n\tInt       null.Int\n\tTime      time.Time\n\tTimeStamp null.Time\n\tTinyInt   int\n\tVarChar   null.String\n}\n`\n\n\tcolumnMap := map[string]map[string]string{\n\t\t\"VarChar\":   {\"nullable\": \"YES\", \"value\": \"varchar\"},\n\t\t\"TinyInt\":   {\"nullable\": \"NO\", \"value\": \"tinyint\"},\n\t\t\"Int\":       {\"nullable\": \"YES\", \"value\": \"int\"},\n\t\t\"BigInt\":    {\"nullable\": \"NO\", \"value\": \"bigint\"},\n\t\t\"Decimal\":   {\"nullable\": \"YES\", \"value\": \"decimal\"},\n\t\t\"Float\":     {\"nullable\": \"YES\", \"value\": \"float\"},\n\t\t\"Double\":    {\"nullable\": \"NO\", \"value\": \"double\"},\n\t\t\"DateTime\":  {\"nullable\": \"YES\", \"value\": \"datetime\"},\n\t\t\"Time\":      {\"nullable\": \"NO\", \"value\": \"time\"},\n\t\t\"Date\":      {\"nullable\": \"YES\", \"value\": \"date\"},\n\t\t\"TimeStamp\": {\"nullable\": \"YES\", \"value\": \"timestamp\"},\n\t}\n\n\tbytes, err := Generate(columnMap, \"test_table\", \"testStruct\", \"test\", false, false, true)\n\n\tConvey(\"Should be able to generate map for guregu types\", t, func() {\n\t\tSo(err, ShouldBeNil)\n\t\tSo(string(bytes), ShouldEqual, expectedStruct)\n\t})\n}\n"
  }
]