mirror of
https://github.com/versia-pub/versia-go.git
synced 2025-12-06 06:28:18 +01:00
chore: init
This commit is contained in:
commit
320715f3e7
14
.env
Normal file
14
.env
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
PUBLIC_ADDRESS="https://localhost"
|
||||
INSTANCE_NAME="lysand-test"
|
||||
INSTANCE_DESCRIPTION="Versia-Go Instance"
|
||||
|
||||
NATS_URI="nats://localhost:4222"
|
||||
|
||||
# SQLite
|
||||
DATABASE_URI="file:./versia-go.db?cache=shared&_fk=1"
|
||||
# PostgreSQL
|
||||
# DATABASE_URI="postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable"
|
||||
|
||||
ENVIRONMENT="development"
|
||||
OTLP_ENDPOINT=""
|
||||
SENTRY_DSN=""
|
||||
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
cert.pem
|
||||
key.pem
|
||||
*.db
|
||||
.env.*
|
||||
662
LICENSE
Normal file
662
LICENSE
Normal file
|
|
@ -0,0 +1,662 @@
|
|||
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
63
README.md
Normal file
63
README.md
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# Versia-Go
|
||||
|
||||
Versia-Go is a experimental implementation of the (not yet renamed :P) [Versia](https://lysand.org) protocol written in
|
||||
Go.
|
||||
|
||||
> Compatibility level: Lysand 3.1 (sort of)
|
||||
|
||||
> ⚠️ This project is still in development and is not ready for production use.
|
||||
|
||||
## Developing
|
||||
|
||||
### Requirements
|
||||
|
||||
- Go 1.22.5+
|
||||
- Docker + Docker Compose v2
|
||||
|
||||
### Running
|
||||
|
||||
```shell
|
||||
git clone https://github.com/lysand/versia-go.git
|
||||
cd versia-go
|
||||
|
||||
docker compose up -d nats
|
||||
|
||||
touch .env.local
|
||||
# Add the changed variables from .env to .env.local
|
||||
|
||||
go run .
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
- [ ] Notes
|
||||
- [ ] API
|
||||
- [ ] Allow choosing the publishing user
|
||||
- [x] Federating notes
|
||||
- [ ] Follows
|
||||
- [ ] API
|
||||
- [x] Automatic follows for public users
|
||||
- [ ] Unfollows (scheduled for Lysand Working Draft 4)
|
||||
- [ ] API
|
||||
- [ ] Users
|
||||
- [ ] API
|
||||
- [x] Create user
|
||||
- [ ] Lysand API
|
||||
- [x] Get user (from local)
|
||||
- [x] Webfinger
|
||||
- [ ] Inbox handling
|
||||
- [ ] Federated notes
|
||||
- [ ] Federated unfollows
|
||||
- [x] Federated follows
|
||||
- [x] Receiving federated users
|
||||
- [ ] Web
|
||||
- Extensions
|
||||
- [ ] Emojis
|
||||
|
||||
## License
|
||||
|
||||
Versia-Go is licensed under the GNU Affero General Public License v3.0.
|
||||
|
||||
See [LICENSE](LICENSE) for more information.
|
||||
|
||||
> ℹ️ This project might get relicensed to a different license in the future.
|
||||
16
compose.yml
Normal file
16
compose.yml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
services:
|
||||
db:
|
||||
image: postgres:16.2-alpine
|
||||
environment:
|
||||
POSTGRES_DB: postgres
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
ports:
|
||||
- "5432:5432"
|
||||
|
||||
nats:
|
||||
image: nats:2.9.25-scratch
|
||||
ports:
|
||||
- "4222:4222"
|
||||
- "8222:8222"
|
||||
command: "--js"
|
||||
55
config/config.go
Normal file
55
config/config.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"git.devminer.xyz/devminer/unitel"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
PublicAddress *url.URL
|
||||
InstanceName string
|
||||
InstanceDescription *string
|
||||
|
||||
NATSURI string
|
||||
DatabaseURI string
|
||||
|
||||
Telemetry unitel.Opts
|
||||
}
|
||||
|
||||
var C Config
|
||||
|
||||
func Load() {
|
||||
if err := godotenv.Load(".env.local", ".env"); err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to load .env file")
|
||||
}
|
||||
|
||||
publicAddress, err := url.Parse(os.Getenv("PUBLIC_ADDRESS"))
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Failed to parse PUBLIC_ADDRESS")
|
||||
}
|
||||
|
||||
C = Config{
|
||||
PublicAddress: publicAddress,
|
||||
InstanceName: os.Getenv("INSTANCE_NAME"),
|
||||
InstanceDescription: optionalEnvStr("INSTANCE_DESCRIPTION"),
|
||||
|
||||
NATSURI: os.Getenv("NATS_URI"),
|
||||
DatabaseURI: os.Getenv("DATABASE_URI"),
|
||||
|
||||
Telemetry: unitel.ParseOpts("versia-go"),
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func optionalEnvStr(key string) *string {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
return nil
|
||||
}
|
||||
return &value
|
||||
}
|
||||
310
ent/attachment.go
Normal file
310
ent/attachment.go
Normal file
|
|
@ -0,0 +1,310 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/attachment"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
// Attachment is the model entity for the Attachment schema.
|
||||
type Attachment struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID uuid.UUID `json:"id,omitempty"`
|
||||
// IsRemote holds the value of the "isRemote" field.
|
||||
IsRemote bool `json:"isRemote,omitempty"`
|
||||
// URI holds the value of the "uri" field.
|
||||
URI string `json:"uri,omitempty"`
|
||||
// Extensions holds the value of the "extensions" field.
|
||||
Extensions lysand.Extensions `json:"extensions,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// Description holds the value of the "description" field.
|
||||
Description string `json:"description,omitempty"`
|
||||
// Sha256 holds the value of the "sha256" field.
|
||||
Sha256 []byte `json:"sha256,omitempty"`
|
||||
// Size holds the value of the "size" field.
|
||||
Size int `json:"size,omitempty"`
|
||||
// Blurhash holds the value of the "blurhash" field.
|
||||
Blurhash *string `json:"blurhash,omitempty"`
|
||||
// Height holds the value of the "height" field.
|
||||
Height *int `json:"height,omitempty"`
|
||||
// Width holds the value of the "width" field.
|
||||
Width *int `json:"width,omitempty"`
|
||||
// Fps holds the value of the "fps" field.
|
||||
Fps *int `json:"fps,omitempty"`
|
||||
// MimeType holds the value of the "mimeType" field.
|
||||
MimeType string `json:"mimeType,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the AttachmentQuery when eager-loading is set.
|
||||
Edges AttachmentEdges `json:"edges"`
|
||||
attachment_author *uuid.UUID
|
||||
note_attachments *uuid.UUID
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// AttachmentEdges holds the relations/edges for other nodes in the graph.
|
||||
type AttachmentEdges struct {
|
||||
// Author holds the value of the author edge.
|
||||
Author *User `json:"author,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// AuthorOrErr returns the Author value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e AttachmentEdges) AuthorOrErr() (*User, error) {
|
||||
if e.Author != nil {
|
||||
return e.Author, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "author"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Attachment) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case attachment.FieldExtensions, attachment.FieldSha256:
|
||||
values[i] = new([]byte)
|
||||
case attachment.FieldIsRemote:
|
||||
values[i] = new(sql.NullBool)
|
||||
case attachment.FieldSize, attachment.FieldHeight, attachment.FieldWidth, attachment.FieldFps:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case attachment.FieldURI, attachment.FieldDescription, attachment.FieldBlurhash, attachment.FieldMimeType:
|
||||
values[i] = new(sql.NullString)
|
||||
case attachment.FieldCreatedAt, attachment.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
case attachment.FieldID:
|
||||
values[i] = new(uuid.UUID)
|
||||
case attachment.ForeignKeys[0]: // attachment_author
|
||||
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
||||
case attachment.ForeignKeys[1]: // note_attachments
|
||||
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Attachment fields.
|
||||
func (a *Attachment) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case attachment.FieldID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||
} else if value != nil {
|
||||
a.ID = *value
|
||||
}
|
||||
case attachment.FieldIsRemote:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field isRemote", values[i])
|
||||
} else if value.Valid {
|
||||
a.IsRemote = value.Bool
|
||||
}
|
||||
case attachment.FieldURI:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uri", values[i])
|
||||
} else if value.Valid {
|
||||
a.URI = value.String
|
||||
}
|
||||
case attachment.FieldExtensions:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field extensions", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &a.Extensions); err != nil {
|
||||
return fmt.Errorf("unmarshal field extensions: %w", err)
|
||||
}
|
||||
}
|
||||
case attachment.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
a.CreatedAt = value.Time
|
||||
}
|
||||
case attachment.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
a.UpdatedAt = value.Time
|
||||
}
|
||||
case attachment.FieldDescription:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field description", values[i])
|
||||
} else if value.Valid {
|
||||
a.Description = value.String
|
||||
}
|
||||
case attachment.FieldSha256:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field sha256", values[i])
|
||||
} else if value != nil {
|
||||
a.Sha256 = *value
|
||||
}
|
||||
case attachment.FieldSize:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field size", values[i])
|
||||
} else if value.Valid {
|
||||
a.Size = int(value.Int64)
|
||||
}
|
||||
case attachment.FieldBlurhash:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field blurhash", values[i])
|
||||
} else if value.Valid {
|
||||
a.Blurhash = new(string)
|
||||
*a.Blurhash = value.String
|
||||
}
|
||||
case attachment.FieldHeight:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field height", values[i])
|
||||
} else if value.Valid {
|
||||
a.Height = new(int)
|
||||
*a.Height = int(value.Int64)
|
||||
}
|
||||
case attachment.FieldWidth:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field width", values[i])
|
||||
} else if value.Valid {
|
||||
a.Width = new(int)
|
||||
*a.Width = int(value.Int64)
|
||||
}
|
||||
case attachment.FieldFps:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field fps", values[i])
|
||||
} else if value.Valid {
|
||||
a.Fps = new(int)
|
||||
*a.Fps = int(value.Int64)
|
||||
}
|
||||
case attachment.FieldMimeType:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field mimeType", values[i])
|
||||
} else if value.Valid {
|
||||
a.MimeType = value.String
|
||||
}
|
||||
case attachment.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullScanner); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field attachment_author", values[i])
|
||||
} else if value.Valid {
|
||||
a.attachment_author = new(uuid.UUID)
|
||||
*a.attachment_author = *value.S.(*uuid.UUID)
|
||||
}
|
||||
case attachment.ForeignKeys[1]:
|
||||
if value, ok := values[i].(*sql.NullScanner); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field note_attachments", values[i])
|
||||
} else if value.Valid {
|
||||
a.note_attachments = new(uuid.UUID)
|
||||
*a.note_attachments = *value.S.(*uuid.UUID)
|
||||
}
|
||||
default:
|
||||
a.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Attachment.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (a *Attachment) Value(name string) (ent.Value, error) {
|
||||
return a.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryAuthor queries the "author" edge of the Attachment entity.
|
||||
func (a *Attachment) QueryAuthor() *UserQuery {
|
||||
return NewAttachmentClient(a.config).QueryAuthor(a)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Attachment.
|
||||
// Note that you need to call Attachment.Unwrap() before calling this method if this Attachment
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (a *Attachment) Update() *AttachmentUpdateOne {
|
||||
return NewAttachmentClient(a.config).UpdateOne(a)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Attachment entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (a *Attachment) Unwrap() *Attachment {
|
||||
_tx, ok := a.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Attachment is not a transactional entity")
|
||||
}
|
||||
a.config.driver = _tx.drv
|
||||
return a
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (a *Attachment) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Attachment(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", a.ID))
|
||||
builder.WriteString("isRemote=")
|
||||
builder.WriteString(fmt.Sprintf("%v", a.IsRemote))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uri=")
|
||||
builder.WriteString(a.URI)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("extensions=")
|
||||
builder.WriteString(fmt.Sprintf("%v", a.Extensions))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(a.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(a.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("description=")
|
||||
builder.WriteString(a.Description)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("sha256=")
|
||||
builder.WriteString(fmt.Sprintf("%v", a.Sha256))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("size=")
|
||||
builder.WriteString(fmt.Sprintf("%v", a.Size))
|
||||
builder.WriteString(", ")
|
||||
if v := a.Blurhash; v != nil {
|
||||
builder.WriteString("blurhash=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := a.Height; v != nil {
|
||||
builder.WriteString("height=")
|
||||
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := a.Width; v != nil {
|
||||
builder.WriteString("width=")
|
||||
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := a.Fps; v != nil {
|
||||
builder.WriteString("fps=")
|
||||
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("mimeType=")
|
||||
builder.WriteString(a.MimeType)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Attachments is a parsable slice of Attachment.
|
||||
type Attachments []*Attachment
|
||||
190
ent/attachment/attachment.go
Normal file
190
ent/attachment/attachment.go
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package attachment
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the attachment type in the database.
|
||||
Label = "attachment"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldIsRemote holds the string denoting the isremote field in the database.
|
||||
FieldIsRemote = "is_remote"
|
||||
// FieldURI holds the string denoting the uri field in the database.
|
||||
FieldURI = "uri"
|
||||
// FieldExtensions holds the string denoting the extensions field in the database.
|
||||
FieldExtensions = "extensions"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldDescription holds the string denoting the description field in the database.
|
||||
FieldDescription = "description"
|
||||
// FieldSha256 holds the string denoting the sha256 field in the database.
|
||||
FieldSha256 = "sha256"
|
||||
// FieldSize holds the string denoting the size field in the database.
|
||||
FieldSize = "size"
|
||||
// FieldBlurhash holds the string denoting the blurhash field in the database.
|
||||
FieldBlurhash = "blurhash"
|
||||
// FieldHeight holds the string denoting the height field in the database.
|
||||
FieldHeight = "height"
|
||||
// FieldWidth holds the string denoting the width field in the database.
|
||||
FieldWidth = "width"
|
||||
// FieldFps holds the string denoting the fps field in the database.
|
||||
FieldFps = "fps"
|
||||
// FieldMimeType holds the string denoting the mimetype field in the database.
|
||||
FieldMimeType = "mime_type"
|
||||
// EdgeAuthor holds the string denoting the author edge name in mutations.
|
||||
EdgeAuthor = "author"
|
||||
// Table holds the table name of the attachment in the database.
|
||||
Table = "attachments"
|
||||
// AuthorTable is the table that holds the author relation/edge.
|
||||
AuthorTable = "attachments"
|
||||
// AuthorInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
AuthorInverseTable = "users"
|
||||
// AuthorColumn is the table column denoting the author relation/edge.
|
||||
AuthorColumn = "attachment_author"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for attachment fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldIsRemote,
|
||||
FieldURI,
|
||||
FieldExtensions,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldDescription,
|
||||
FieldSha256,
|
||||
FieldSize,
|
||||
FieldBlurhash,
|
||||
FieldHeight,
|
||||
FieldWidth,
|
||||
FieldFps,
|
||||
FieldMimeType,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "attachments"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"attachment_author",
|
||||
"note_attachments",
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
URIValidator func(string) error
|
||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
||||
DefaultExtensions lysand.Extensions
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time
|
||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||
UpdateDefaultUpdatedAt func() time.Time
|
||||
// DescriptionValidator is a validator for the "description" field. It is called by the builders before save.
|
||||
DescriptionValidator func(string) error
|
||||
// DefaultID holds the default value on creation for the "id" field.
|
||||
DefaultID func() uuid.UUID
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the Attachment queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByIsRemote orders the results by the isRemote field.
|
||||
func ByIsRemote(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldIsRemote, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByURI orders the results by the uri field.
|
||||
func ByURI(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldURI, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDescription orders the results by the description field.
|
||||
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDescription, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// BySize orders the results by the size field.
|
||||
func BySize(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSize, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByBlurhash orders the results by the blurhash field.
|
||||
func ByBlurhash(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldBlurhash, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByHeight orders the results by the height field.
|
||||
func ByHeight(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldHeight, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByWidth orders the results by the width field.
|
||||
func ByWidth(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldWidth, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByFps orders the results by the fps field.
|
||||
func ByFps(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldFps, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByMimeType orders the results by the mimeType field.
|
||||
func ByMimeType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldMimeType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAuthorField orders the results by author field.
|
||||
func ByAuthorField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newAuthorStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newAuthorStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(AuthorInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, AuthorTable, AuthorColumn),
|
||||
)
|
||||
}
|
||||
745
ent/attachment/where.go
Normal file
745
ent/attachment/where.go
Normal file
|
|
@ -0,0 +1,745 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package attachment
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id uuid.UUID) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id uuid.UUID) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id uuid.UUID) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...uuid.UUID) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...uuid.UUID) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id uuid.UUID) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id uuid.UUID) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id uuid.UUID) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id uuid.UUID) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IsRemote applies equality check predicate on the "isRemote" field. It's identical to IsRemoteEQ.
|
||||
func IsRemote(v bool) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldIsRemote, v))
|
||||
}
|
||||
|
||||
// URI applies equality check predicate on the "uri" field. It's identical to URIEQ.
|
||||
func URI(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldURI, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
|
||||
func Description(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// Sha256 applies equality check predicate on the "sha256" field. It's identical to Sha256EQ.
|
||||
func Sha256(v []byte) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldSha256, v))
|
||||
}
|
||||
|
||||
// Size applies equality check predicate on the "size" field. It's identical to SizeEQ.
|
||||
func Size(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldSize, v))
|
||||
}
|
||||
|
||||
// Blurhash applies equality check predicate on the "blurhash" field. It's identical to BlurhashEQ.
|
||||
func Blurhash(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldBlurhash, v))
|
||||
}
|
||||
|
||||
// Height applies equality check predicate on the "height" field. It's identical to HeightEQ.
|
||||
func Height(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldHeight, v))
|
||||
}
|
||||
|
||||
// Width applies equality check predicate on the "width" field. It's identical to WidthEQ.
|
||||
func Width(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldWidth, v))
|
||||
}
|
||||
|
||||
// Fps applies equality check predicate on the "fps" field. It's identical to FpsEQ.
|
||||
func Fps(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldFps, v))
|
||||
}
|
||||
|
||||
// MimeType applies equality check predicate on the "mimeType" field. It's identical to MimeTypeEQ.
|
||||
func MimeType(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// IsRemoteEQ applies the EQ predicate on the "isRemote" field.
|
||||
func IsRemoteEQ(v bool) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldIsRemote, v))
|
||||
}
|
||||
|
||||
// IsRemoteNEQ applies the NEQ predicate on the "isRemote" field.
|
||||
func IsRemoteNEQ(v bool) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldIsRemote, v))
|
||||
}
|
||||
|
||||
// URIEQ applies the EQ predicate on the "uri" field.
|
||||
func URIEQ(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldURI, v))
|
||||
}
|
||||
|
||||
// URINEQ applies the NEQ predicate on the "uri" field.
|
||||
func URINEQ(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIIn applies the In predicate on the "uri" field.
|
||||
func URIIn(vs ...string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIn(FieldURI, vs...))
|
||||
}
|
||||
|
||||
// URINotIn applies the NotIn predicate on the "uri" field.
|
||||
func URINotIn(vs ...string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotIn(FieldURI, vs...))
|
||||
}
|
||||
|
||||
// URIGT applies the GT predicate on the "uri" field.
|
||||
func URIGT(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGT(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIGTE applies the GTE predicate on the "uri" field.
|
||||
func URIGTE(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGTE(FieldURI, v))
|
||||
}
|
||||
|
||||
// URILT applies the LT predicate on the "uri" field.
|
||||
func URILT(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLT(FieldURI, v))
|
||||
}
|
||||
|
||||
// URILTE applies the LTE predicate on the "uri" field.
|
||||
func URILTE(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLTE(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIContains applies the Contains predicate on the "uri" field.
|
||||
func URIContains(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldContains(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIHasPrefix applies the HasPrefix predicate on the "uri" field.
|
||||
func URIHasPrefix(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldHasPrefix(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIHasSuffix applies the HasSuffix predicate on the "uri" field.
|
||||
func URIHasSuffix(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldHasSuffix(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIEqualFold applies the EqualFold predicate on the "uri" field.
|
||||
func URIEqualFold(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEqualFold(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIContainsFold applies the ContainsFold predicate on the "uri" field.
|
||||
func URIContainsFold(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldContainsFold(FieldURI, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// DescriptionEQ applies the EQ predicate on the "description" field.
|
||||
func DescriptionEQ(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionNEQ applies the NEQ predicate on the "description" field.
|
||||
func DescriptionNEQ(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionIn applies the In predicate on the "description" field.
|
||||
func DescriptionIn(vs ...string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIn(FieldDescription, vs...))
|
||||
}
|
||||
|
||||
// DescriptionNotIn applies the NotIn predicate on the "description" field.
|
||||
func DescriptionNotIn(vs ...string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotIn(FieldDescription, vs...))
|
||||
}
|
||||
|
||||
// DescriptionGT applies the GT predicate on the "description" field.
|
||||
func DescriptionGT(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGT(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionGTE applies the GTE predicate on the "description" field.
|
||||
func DescriptionGTE(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGTE(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionLT applies the LT predicate on the "description" field.
|
||||
func DescriptionLT(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLT(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionLTE applies the LTE predicate on the "description" field.
|
||||
func DescriptionLTE(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLTE(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionContains applies the Contains predicate on the "description" field.
|
||||
func DescriptionContains(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldContains(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
|
||||
func DescriptionHasPrefix(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldHasPrefix(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
|
||||
func DescriptionHasSuffix(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldHasSuffix(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
|
||||
func DescriptionEqualFold(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEqualFold(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
|
||||
func DescriptionContainsFold(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldContainsFold(FieldDescription, v))
|
||||
}
|
||||
|
||||
// Sha256EQ applies the EQ predicate on the "sha256" field.
|
||||
func Sha256EQ(v []byte) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldSha256, v))
|
||||
}
|
||||
|
||||
// Sha256NEQ applies the NEQ predicate on the "sha256" field.
|
||||
func Sha256NEQ(v []byte) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldSha256, v))
|
||||
}
|
||||
|
||||
// Sha256In applies the In predicate on the "sha256" field.
|
||||
func Sha256In(vs ...[]byte) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIn(FieldSha256, vs...))
|
||||
}
|
||||
|
||||
// Sha256NotIn applies the NotIn predicate on the "sha256" field.
|
||||
func Sha256NotIn(vs ...[]byte) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotIn(FieldSha256, vs...))
|
||||
}
|
||||
|
||||
// Sha256GT applies the GT predicate on the "sha256" field.
|
||||
func Sha256GT(v []byte) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGT(FieldSha256, v))
|
||||
}
|
||||
|
||||
// Sha256GTE applies the GTE predicate on the "sha256" field.
|
||||
func Sha256GTE(v []byte) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGTE(FieldSha256, v))
|
||||
}
|
||||
|
||||
// Sha256LT applies the LT predicate on the "sha256" field.
|
||||
func Sha256LT(v []byte) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLT(FieldSha256, v))
|
||||
}
|
||||
|
||||
// Sha256LTE applies the LTE predicate on the "sha256" field.
|
||||
func Sha256LTE(v []byte) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLTE(FieldSha256, v))
|
||||
}
|
||||
|
||||
// SizeEQ applies the EQ predicate on the "size" field.
|
||||
func SizeEQ(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldSize, v))
|
||||
}
|
||||
|
||||
// SizeNEQ applies the NEQ predicate on the "size" field.
|
||||
func SizeNEQ(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldSize, v))
|
||||
}
|
||||
|
||||
// SizeIn applies the In predicate on the "size" field.
|
||||
func SizeIn(vs ...int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIn(FieldSize, vs...))
|
||||
}
|
||||
|
||||
// SizeNotIn applies the NotIn predicate on the "size" field.
|
||||
func SizeNotIn(vs ...int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotIn(FieldSize, vs...))
|
||||
}
|
||||
|
||||
// SizeGT applies the GT predicate on the "size" field.
|
||||
func SizeGT(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGT(FieldSize, v))
|
||||
}
|
||||
|
||||
// SizeGTE applies the GTE predicate on the "size" field.
|
||||
func SizeGTE(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGTE(FieldSize, v))
|
||||
}
|
||||
|
||||
// SizeLT applies the LT predicate on the "size" field.
|
||||
func SizeLT(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLT(FieldSize, v))
|
||||
}
|
||||
|
||||
// SizeLTE applies the LTE predicate on the "size" field.
|
||||
func SizeLTE(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLTE(FieldSize, v))
|
||||
}
|
||||
|
||||
// BlurhashEQ applies the EQ predicate on the "blurhash" field.
|
||||
func BlurhashEQ(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldBlurhash, v))
|
||||
}
|
||||
|
||||
// BlurhashNEQ applies the NEQ predicate on the "blurhash" field.
|
||||
func BlurhashNEQ(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldBlurhash, v))
|
||||
}
|
||||
|
||||
// BlurhashIn applies the In predicate on the "blurhash" field.
|
||||
func BlurhashIn(vs ...string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIn(FieldBlurhash, vs...))
|
||||
}
|
||||
|
||||
// BlurhashNotIn applies the NotIn predicate on the "blurhash" field.
|
||||
func BlurhashNotIn(vs ...string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotIn(FieldBlurhash, vs...))
|
||||
}
|
||||
|
||||
// BlurhashGT applies the GT predicate on the "blurhash" field.
|
||||
func BlurhashGT(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGT(FieldBlurhash, v))
|
||||
}
|
||||
|
||||
// BlurhashGTE applies the GTE predicate on the "blurhash" field.
|
||||
func BlurhashGTE(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGTE(FieldBlurhash, v))
|
||||
}
|
||||
|
||||
// BlurhashLT applies the LT predicate on the "blurhash" field.
|
||||
func BlurhashLT(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLT(FieldBlurhash, v))
|
||||
}
|
||||
|
||||
// BlurhashLTE applies the LTE predicate on the "blurhash" field.
|
||||
func BlurhashLTE(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLTE(FieldBlurhash, v))
|
||||
}
|
||||
|
||||
// BlurhashContains applies the Contains predicate on the "blurhash" field.
|
||||
func BlurhashContains(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldContains(FieldBlurhash, v))
|
||||
}
|
||||
|
||||
// BlurhashHasPrefix applies the HasPrefix predicate on the "blurhash" field.
|
||||
func BlurhashHasPrefix(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldHasPrefix(FieldBlurhash, v))
|
||||
}
|
||||
|
||||
// BlurhashHasSuffix applies the HasSuffix predicate on the "blurhash" field.
|
||||
func BlurhashHasSuffix(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldHasSuffix(FieldBlurhash, v))
|
||||
}
|
||||
|
||||
// BlurhashIsNil applies the IsNil predicate on the "blurhash" field.
|
||||
func BlurhashIsNil() predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIsNull(FieldBlurhash))
|
||||
}
|
||||
|
||||
// BlurhashNotNil applies the NotNil predicate on the "blurhash" field.
|
||||
func BlurhashNotNil() predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotNull(FieldBlurhash))
|
||||
}
|
||||
|
||||
// BlurhashEqualFold applies the EqualFold predicate on the "blurhash" field.
|
||||
func BlurhashEqualFold(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEqualFold(FieldBlurhash, v))
|
||||
}
|
||||
|
||||
// BlurhashContainsFold applies the ContainsFold predicate on the "blurhash" field.
|
||||
func BlurhashContainsFold(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldContainsFold(FieldBlurhash, v))
|
||||
}
|
||||
|
||||
// HeightEQ applies the EQ predicate on the "height" field.
|
||||
func HeightEQ(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldHeight, v))
|
||||
}
|
||||
|
||||
// HeightNEQ applies the NEQ predicate on the "height" field.
|
||||
func HeightNEQ(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldHeight, v))
|
||||
}
|
||||
|
||||
// HeightIn applies the In predicate on the "height" field.
|
||||
func HeightIn(vs ...int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIn(FieldHeight, vs...))
|
||||
}
|
||||
|
||||
// HeightNotIn applies the NotIn predicate on the "height" field.
|
||||
func HeightNotIn(vs ...int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotIn(FieldHeight, vs...))
|
||||
}
|
||||
|
||||
// HeightGT applies the GT predicate on the "height" field.
|
||||
func HeightGT(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGT(FieldHeight, v))
|
||||
}
|
||||
|
||||
// HeightGTE applies the GTE predicate on the "height" field.
|
||||
func HeightGTE(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGTE(FieldHeight, v))
|
||||
}
|
||||
|
||||
// HeightLT applies the LT predicate on the "height" field.
|
||||
func HeightLT(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLT(FieldHeight, v))
|
||||
}
|
||||
|
||||
// HeightLTE applies the LTE predicate on the "height" field.
|
||||
func HeightLTE(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLTE(FieldHeight, v))
|
||||
}
|
||||
|
||||
// HeightIsNil applies the IsNil predicate on the "height" field.
|
||||
func HeightIsNil() predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIsNull(FieldHeight))
|
||||
}
|
||||
|
||||
// HeightNotNil applies the NotNil predicate on the "height" field.
|
||||
func HeightNotNil() predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotNull(FieldHeight))
|
||||
}
|
||||
|
||||
// WidthEQ applies the EQ predicate on the "width" field.
|
||||
func WidthEQ(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldWidth, v))
|
||||
}
|
||||
|
||||
// WidthNEQ applies the NEQ predicate on the "width" field.
|
||||
func WidthNEQ(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldWidth, v))
|
||||
}
|
||||
|
||||
// WidthIn applies the In predicate on the "width" field.
|
||||
func WidthIn(vs ...int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIn(FieldWidth, vs...))
|
||||
}
|
||||
|
||||
// WidthNotIn applies the NotIn predicate on the "width" field.
|
||||
func WidthNotIn(vs ...int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotIn(FieldWidth, vs...))
|
||||
}
|
||||
|
||||
// WidthGT applies the GT predicate on the "width" field.
|
||||
func WidthGT(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGT(FieldWidth, v))
|
||||
}
|
||||
|
||||
// WidthGTE applies the GTE predicate on the "width" field.
|
||||
func WidthGTE(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGTE(FieldWidth, v))
|
||||
}
|
||||
|
||||
// WidthLT applies the LT predicate on the "width" field.
|
||||
func WidthLT(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLT(FieldWidth, v))
|
||||
}
|
||||
|
||||
// WidthLTE applies the LTE predicate on the "width" field.
|
||||
func WidthLTE(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLTE(FieldWidth, v))
|
||||
}
|
||||
|
||||
// WidthIsNil applies the IsNil predicate on the "width" field.
|
||||
func WidthIsNil() predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIsNull(FieldWidth))
|
||||
}
|
||||
|
||||
// WidthNotNil applies the NotNil predicate on the "width" field.
|
||||
func WidthNotNil() predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotNull(FieldWidth))
|
||||
}
|
||||
|
||||
// FpsEQ applies the EQ predicate on the "fps" field.
|
||||
func FpsEQ(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldFps, v))
|
||||
}
|
||||
|
||||
// FpsNEQ applies the NEQ predicate on the "fps" field.
|
||||
func FpsNEQ(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldFps, v))
|
||||
}
|
||||
|
||||
// FpsIn applies the In predicate on the "fps" field.
|
||||
func FpsIn(vs ...int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIn(FieldFps, vs...))
|
||||
}
|
||||
|
||||
// FpsNotIn applies the NotIn predicate on the "fps" field.
|
||||
func FpsNotIn(vs ...int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotIn(FieldFps, vs...))
|
||||
}
|
||||
|
||||
// FpsGT applies the GT predicate on the "fps" field.
|
||||
func FpsGT(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGT(FieldFps, v))
|
||||
}
|
||||
|
||||
// FpsGTE applies the GTE predicate on the "fps" field.
|
||||
func FpsGTE(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGTE(FieldFps, v))
|
||||
}
|
||||
|
||||
// FpsLT applies the LT predicate on the "fps" field.
|
||||
func FpsLT(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLT(FieldFps, v))
|
||||
}
|
||||
|
||||
// FpsLTE applies the LTE predicate on the "fps" field.
|
||||
func FpsLTE(v int) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLTE(FieldFps, v))
|
||||
}
|
||||
|
||||
// FpsIsNil applies the IsNil predicate on the "fps" field.
|
||||
func FpsIsNil() predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIsNull(FieldFps))
|
||||
}
|
||||
|
||||
// FpsNotNil applies the NotNil predicate on the "fps" field.
|
||||
func FpsNotNil() predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotNull(FieldFps))
|
||||
}
|
||||
|
||||
// MimeTypeEQ applies the EQ predicate on the "mimeType" field.
|
||||
func MimeTypeEQ(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEQ(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeNEQ applies the NEQ predicate on the "mimeType" field.
|
||||
func MimeTypeNEQ(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNEQ(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeIn applies the In predicate on the "mimeType" field.
|
||||
func MimeTypeIn(vs ...string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldIn(FieldMimeType, vs...))
|
||||
}
|
||||
|
||||
// MimeTypeNotIn applies the NotIn predicate on the "mimeType" field.
|
||||
func MimeTypeNotIn(vs ...string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldNotIn(FieldMimeType, vs...))
|
||||
}
|
||||
|
||||
// MimeTypeGT applies the GT predicate on the "mimeType" field.
|
||||
func MimeTypeGT(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGT(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeGTE applies the GTE predicate on the "mimeType" field.
|
||||
func MimeTypeGTE(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldGTE(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeLT applies the LT predicate on the "mimeType" field.
|
||||
func MimeTypeLT(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLT(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeLTE applies the LTE predicate on the "mimeType" field.
|
||||
func MimeTypeLTE(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldLTE(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeContains applies the Contains predicate on the "mimeType" field.
|
||||
func MimeTypeContains(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldContains(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeHasPrefix applies the HasPrefix predicate on the "mimeType" field.
|
||||
func MimeTypeHasPrefix(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldHasPrefix(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeHasSuffix applies the HasSuffix predicate on the "mimeType" field.
|
||||
func MimeTypeHasSuffix(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldHasSuffix(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeEqualFold applies the EqualFold predicate on the "mimeType" field.
|
||||
func MimeTypeEqualFold(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldEqualFold(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeContainsFold applies the ContainsFold predicate on the "mimeType" field.
|
||||
func MimeTypeContainsFold(v string) predicate.Attachment {
|
||||
return predicate.Attachment(sql.FieldContainsFold(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// HasAuthor applies the HasEdge predicate on the "author" edge.
|
||||
func HasAuthor() predicate.Attachment {
|
||||
return predicate.Attachment(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, AuthorTable, AuthorColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasAuthorWith applies the HasEdge predicate on the "author" edge with a given conditions (other predicates).
|
||||
func HasAuthorWith(preds ...predicate.User) predicate.Attachment {
|
||||
return predicate.Attachment(func(s *sql.Selector) {
|
||||
step := newAuthorStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Attachment) predicate.Attachment {
|
||||
return predicate.Attachment(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Attachment) predicate.Attachment {
|
||||
return predicate.Attachment(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Attachment) predicate.Attachment {
|
||||
return predicate.Attachment(sql.NotPredicates(p))
|
||||
}
|
||||
1362
ent/attachment_create.go
Normal file
1362
ent/attachment_create.go
Normal file
File diff suppressed because it is too large
Load diff
88
ent/attachment_delete.go
Normal file
88
ent/attachment_delete.go
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/lysand-org/versia-go/ent/attachment"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
)
|
||||
|
||||
// AttachmentDelete is the builder for deleting a Attachment entity.
|
||||
type AttachmentDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *AttachmentMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the AttachmentDelete builder.
|
||||
func (ad *AttachmentDelete) Where(ps ...predicate.Attachment) *AttachmentDelete {
|
||||
ad.mutation.Where(ps...)
|
||||
return ad
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (ad *AttachmentDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, ad.sqlExec, ad.mutation, ad.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ad *AttachmentDelete) ExecX(ctx context.Context) int {
|
||||
n, err := ad.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (ad *AttachmentDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(attachment.Table, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID))
|
||||
if ps := ad.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, ad.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
ad.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// AttachmentDeleteOne is the builder for deleting a single Attachment entity.
|
||||
type AttachmentDeleteOne struct {
|
||||
ad *AttachmentDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the AttachmentDelete builder.
|
||||
func (ado *AttachmentDeleteOne) Where(ps ...predicate.Attachment) *AttachmentDeleteOne {
|
||||
ado.ad.mutation.Where(ps...)
|
||||
return ado
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (ado *AttachmentDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := ado.ad.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{attachment.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ado *AttachmentDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := ado.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
614
ent/attachment_query.go
Normal file
614
ent/attachment_query.go
Normal file
|
|
@ -0,0 +1,614 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/attachment"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
)
|
||||
|
||||
// AttachmentQuery is the builder for querying Attachment entities.
|
||||
type AttachmentQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []attachment.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Attachment
|
||||
withAuthor *UserQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the AttachmentQuery builder.
|
||||
func (aq *AttachmentQuery) Where(ps ...predicate.Attachment) *AttachmentQuery {
|
||||
aq.predicates = append(aq.predicates, ps...)
|
||||
return aq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (aq *AttachmentQuery) Limit(limit int) *AttachmentQuery {
|
||||
aq.ctx.Limit = &limit
|
||||
return aq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (aq *AttachmentQuery) Offset(offset int) *AttachmentQuery {
|
||||
aq.ctx.Offset = &offset
|
||||
return aq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (aq *AttachmentQuery) Unique(unique bool) *AttachmentQuery {
|
||||
aq.ctx.Unique = &unique
|
||||
return aq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (aq *AttachmentQuery) Order(o ...attachment.OrderOption) *AttachmentQuery {
|
||||
aq.order = append(aq.order, o...)
|
||||
return aq
|
||||
}
|
||||
|
||||
// QueryAuthor chains the current query on the "author" edge.
|
||||
func (aq *AttachmentQuery) QueryAuthor() *UserQuery {
|
||||
query := (&UserClient{config: aq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := aq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := aq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(attachment.Table, attachment.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, attachment.AuthorTable, attachment.AuthorColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Attachment entity from the query.
|
||||
// Returns a *NotFoundError when no Attachment was found.
|
||||
func (aq *AttachmentQuery) First(ctx context.Context) (*Attachment, error) {
|
||||
nodes, err := aq.Limit(1).All(setContextOp(ctx, aq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{attachment.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (aq *AttachmentQuery) FirstX(ctx context.Context) *Attachment {
|
||||
node, err := aq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Attachment ID from the query.
|
||||
// Returns a *NotFoundError when no Attachment ID was found.
|
||||
func (aq *AttachmentQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = aq.Limit(1).IDs(setContextOp(ctx, aq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{attachment.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (aq *AttachmentQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := aq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Attachment entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Attachment entity is found.
|
||||
// Returns a *NotFoundError when no Attachment entities are found.
|
||||
func (aq *AttachmentQuery) Only(ctx context.Context) (*Attachment, error) {
|
||||
nodes, err := aq.Limit(2).All(setContextOp(ctx, aq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{attachment.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{attachment.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (aq *AttachmentQuery) OnlyX(ctx context.Context) *Attachment {
|
||||
node, err := aq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Attachment ID in the query.
|
||||
// Returns a *NotSingularError when more than one Attachment ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (aq *AttachmentQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = aq.Limit(2).IDs(setContextOp(ctx, aq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{attachment.Label}
|
||||
default:
|
||||
err = &NotSingularError{attachment.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (aq *AttachmentQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := aq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Attachments.
|
||||
func (aq *AttachmentQuery) All(ctx context.Context) ([]*Attachment, error) {
|
||||
ctx = setContextOp(ctx, aq.ctx, "All")
|
||||
if err := aq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Attachment, *AttachmentQuery]()
|
||||
return withInterceptors[[]*Attachment](ctx, aq, qr, aq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (aq *AttachmentQuery) AllX(ctx context.Context) []*Attachment {
|
||||
nodes, err := aq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Attachment IDs.
|
||||
func (aq *AttachmentQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||
if aq.ctx.Unique == nil && aq.path != nil {
|
||||
aq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, aq.ctx, "IDs")
|
||||
if err = aq.Select(attachment.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (aq *AttachmentQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||
ids, err := aq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (aq *AttachmentQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, aq.ctx, "Count")
|
||||
if err := aq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, aq, querierCount[*AttachmentQuery](), aq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (aq *AttachmentQuery) CountX(ctx context.Context) int {
|
||||
count, err := aq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (aq *AttachmentQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, aq.ctx, "Exist")
|
||||
switch _, err := aq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (aq *AttachmentQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := aq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the AttachmentQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (aq *AttachmentQuery) Clone() *AttachmentQuery {
|
||||
if aq == nil {
|
||||
return nil
|
||||
}
|
||||
return &AttachmentQuery{
|
||||
config: aq.config,
|
||||
ctx: aq.ctx.Clone(),
|
||||
order: append([]attachment.OrderOption{}, aq.order...),
|
||||
inters: append([]Interceptor{}, aq.inters...),
|
||||
predicates: append([]predicate.Attachment{}, aq.predicates...),
|
||||
withAuthor: aq.withAuthor.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: aq.sql.Clone(),
|
||||
path: aq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithAuthor tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "author" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (aq *AttachmentQuery) WithAuthor(opts ...func(*UserQuery)) *AttachmentQuery {
|
||||
query := (&UserClient{config: aq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
aq.withAuthor = query
|
||||
return aq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// IsRemote bool `json:"isRemote,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Attachment.Query().
|
||||
// GroupBy(attachment.FieldIsRemote).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (aq *AttachmentQuery) GroupBy(field string, fields ...string) *AttachmentGroupBy {
|
||||
aq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &AttachmentGroupBy{build: aq}
|
||||
grbuild.flds = &aq.ctx.Fields
|
||||
grbuild.label = attachment.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// IsRemote bool `json:"isRemote,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Attachment.Query().
|
||||
// Select(attachment.FieldIsRemote).
|
||||
// Scan(ctx, &v)
|
||||
func (aq *AttachmentQuery) Select(fields ...string) *AttachmentSelect {
|
||||
aq.ctx.Fields = append(aq.ctx.Fields, fields...)
|
||||
sbuild := &AttachmentSelect{AttachmentQuery: aq}
|
||||
sbuild.label = attachment.Label
|
||||
sbuild.flds, sbuild.scan = &aq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a AttachmentSelect configured with the given aggregations.
|
||||
func (aq *AttachmentQuery) Aggregate(fns ...AggregateFunc) *AttachmentSelect {
|
||||
return aq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (aq *AttachmentQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range aq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, aq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range aq.ctx.Fields {
|
||||
if !attachment.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if aq.path != nil {
|
||||
prev, err := aq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
aq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (aq *AttachmentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Attachment, error) {
|
||||
var (
|
||||
nodes = []*Attachment{}
|
||||
withFKs = aq.withFKs
|
||||
_spec = aq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
aq.withAuthor != nil,
|
||||
}
|
||||
)
|
||||
if aq.withAuthor != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, attachment.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Attachment).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Attachment{config: aq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, aq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := aq.withAuthor; query != nil {
|
||||
if err := aq.loadAuthor(ctx, query, nodes, nil,
|
||||
func(n *Attachment, e *User) { n.Edges.Author = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (aq *AttachmentQuery) loadAuthor(ctx context.Context, query *UserQuery, nodes []*Attachment, init func(*Attachment), assign func(*Attachment, *User)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*Attachment)
|
||||
for i := range nodes {
|
||||
if nodes[i].attachment_author == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].attachment_author
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "attachment_author" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (aq *AttachmentQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := aq.querySpec()
|
||||
_spec.Node.Columns = aq.ctx.Fields
|
||||
if len(aq.ctx.Fields) > 0 {
|
||||
_spec.Unique = aq.ctx.Unique != nil && *aq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, aq.driver, _spec)
|
||||
}
|
||||
|
||||
func (aq *AttachmentQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID))
|
||||
_spec.From = aq.sql
|
||||
if unique := aq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if aq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := aq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, attachment.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != attachment.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := aq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := aq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := aq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := aq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (aq *AttachmentQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(aq.driver.Dialect())
|
||||
t1 := builder.Table(attachment.Table)
|
||||
columns := aq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = attachment.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if aq.sql != nil {
|
||||
selector = aq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if aq.ctx.Unique != nil && *aq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range aq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range aq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := aq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := aq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// AttachmentGroupBy is the group-by builder for Attachment entities.
|
||||
type AttachmentGroupBy struct {
|
||||
selector
|
||||
build *AttachmentQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (agb *AttachmentGroupBy) Aggregate(fns ...AggregateFunc) *AttachmentGroupBy {
|
||||
agb.fns = append(agb.fns, fns...)
|
||||
return agb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (agb *AttachmentGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, agb.build.ctx, "GroupBy")
|
||||
if err := agb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*AttachmentQuery, *AttachmentGroupBy](ctx, agb.build, agb, agb.build.inters, v)
|
||||
}
|
||||
|
||||
func (agb *AttachmentGroupBy) sqlScan(ctx context.Context, root *AttachmentQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(agb.fns))
|
||||
for _, fn := range agb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*agb.flds)+len(agb.fns))
|
||||
for _, f := range *agb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*agb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := agb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// AttachmentSelect is the builder for selecting fields of Attachment entities.
|
||||
type AttachmentSelect struct {
|
||||
*AttachmentQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (as *AttachmentSelect) Aggregate(fns ...AggregateFunc) *AttachmentSelect {
|
||||
as.fns = append(as.fns, fns...)
|
||||
return as
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (as *AttachmentSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, as.ctx, "Select")
|
||||
if err := as.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*AttachmentQuery, *AttachmentSelect](ctx, as.AttachmentQuery, as, as.inters, v)
|
||||
}
|
||||
|
||||
func (as *AttachmentSelect) sqlScan(ctx context.Context, root *AttachmentQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(as.fns))
|
||||
for _, fn := range as.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*as.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := as.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
843
ent/attachment_update.go
Normal file
843
ent/attachment_update.go
Normal file
|
|
@ -0,0 +1,843 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/attachment"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
// AttachmentUpdate is the builder for updating Attachment entities.
|
||||
type AttachmentUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *AttachmentMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the AttachmentUpdate builder.
|
||||
func (au *AttachmentUpdate) Where(ps ...predicate.Attachment) *AttachmentUpdate {
|
||||
au.mutation.Where(ps...)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetIsRemote sets the "isRemote" field.
|
||||
func (au *AttachmentUpdate) SetIsRemote(b bool) *AttachmentUpdate {
|
||||
au.mutation.SetIsRemote(b)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetNillableIsRemote sets the "isRemote" field if the given value is not nil.
|
||||
func (au *AttachmentUpdate) SetNillableIsRemote(b *bool) *AttachmentUpdate {
|
||||
if b != nil {
|
||||
au.SetIsRemote(*b)
|
||||
}
|
||||
return au
|
||||
}
|
||||
|
||||
// SetURI sets the "uri" field.
|
||||
func (au *AttachmentUpdate) SetURI(s string) *AttachmentUpdate {
|
||||
au.mutation.SetURI(s)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetNillableURI sets the "uri" field if the given value is not nil.
|
||||
func (au *AttachmentUpdate) SetNillableURI(s *string) *AttachmentUpdate {
|
||||
if s != nil {
|
||||
au.SetURI(*s)
|
||||
}
|
||||
return au
|
||||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (au *AttachmentUpdate) SetExtensions(l lysand.Extensions) *AttachmentUpdate {
|
||||
au.mutation.SetExtensions(l)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (au *AttachmentUpdate) SetUpdatedAt(t time.Time) *AttachmentUpdate {
|
||||
au.mutation.SetUpdatedAt(t)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (au *AttachmentUpdate) SetDescription(s string) *AttachmentUpdate {
|
||||
au.mutation.SetDescription(s)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (au *AttachmentUpdate) SetNillableDescription(s *string) *AttachmentUpdate {
|
||||
if s != nil {
|
||||
au.SetDescription(*s)
|
||||
}
|
||||
return au
|
||||
}
|
||||
|
||||
// SetSha256 sets the "sha256" field.
|
||||
func (au *AttachmentUpdate) SetSha256(b []byte) *AttachmentUpdate {
|
||||
au.mutation.SetSha256(b)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetSize sets the "size" field.
|
||||
func (au *AttachmentUpdate) SetSize(i int) *AttachmentUpdate {
|
||||
au.mutation.ResetSize()
|
||||
au.mutation.SetSize(i)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetNillableSize sets the "size" field if the given value is not nil.
|
||||
func (au *AttachmentUpdate) SetNillableSize(i *int) *AttachmentUpdate {
|
||||
if i != nil {
|
||||
au.SetSize(*i)
|
||||
}
|
||||
return au
|
||||
}
|
||||
|
||||
// AddSize adds i to the "size" field.
|
||||
func (au *AttachmentUpdate) AddSize(i int) *AttachmentUpdate {
|
||||
au.mutation.AddSize(i)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetBlurhash sets the "blurhash" field.
|
||||
func (au *AttachmentUpdate) SetBlurhash(s string) *AttachmentUpdate {
|
||||
au.mutation.SetBlurhash(s)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetNillableBlurhash sets the "blurhash" field if the given value is not nil.
|
||||
func (au *AttachmentUpdate) SetNillableBlurhash(s *string) *AttachmentUpdate {
|
||||
if s != nil {
|
||||
au.SetBlurhash(*s)
|
||||
}
|
||||
return au
|
||||
}
|
||||
|
||||
// ClearBlurhash clears the value of the "blurhash" field.
|
||||
func (au *AttachmentUpdate) ClearBlurhash() *AttachmentUpdate {
|
||||
au.mutation.ClearBlurhash()
|
||||
return au
|
||||
}
|
||||
|
||||
// SetHeight sets the "height" field.
|
||||
func (au *AttachmentUpdate) SetHeight(i int) *AttachmentUpdate {
|
||||
au.mutation.ResetHeight()
|
||||
au.mutation.SetHeight(i)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetNillableHeight sets the "height" field if the given value is not nil.
|
||||
func (au *AttachmentUpdate) SetNillableHeight(i *int) *AttachmentUpdate {
|
||||
if i != nil {
|
||||
au.SetHeight(*i)
|
||||
}
|
||||
return au
|
||||
}
|
||||
|
||||
// AddHeight adds i to the "height" field.
|
||||
func (au *AttachmentUpdate) AddHeight(i int) *AttachmentUpdate {
|
||||
au.mutation.AddHeight(i)
|
||||
return au
|
||||
}
|
||||
|
||||
// ClearHeight clears the value of the "height" field.
|
||||
func (au *AttachmentUpdate) ClearHeight() *AttachmentUpdate {
|
||||
au.mutation.ClearHeight()
|
||||
return au
|
||||
}
|
||||
|
||||
// SetWidth sets the "width" field.
|
||||
func (au *AttachmentUpdate) SetWidth(i int) *AttachmentUpdate {
|
||||
au.mutation.ResetWidth()
|
||||
au.mutation.SetWidth(i)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetNillableWidth sets the "width" field if the given value is not nil.
|
||||
func (au *AttachmentUpdate) SetNillableWidth(i *int) *AttachmentUpdate {
|
||||
if i != nil {
|
||||
au.SetWidth(*i)
|
||||
}
|
||||
return au
|
||||
}
|
||||
|
||||
// AddWidth adds i to the "width" field.
|
||||
func (au *AttachmentUpdate) AddWidth(i int) *AttachmentUpdate {
|
||||
au.mutation.AddWidth(i)
|
||||
return au
|
||||
}
|
||||
|
||||
// ClearWidth clears the value of the "width" field.
|
||||
func (au *AttachmentUpdate) ClearWidth() *AttachmentUpdate {
|
||||
au.mutation.ClearWidth()
|
||||
return au
|
||||
}
|
||||
|
||||
// SetFps sets the "fps" field.
|
||||
func (au *AttachmentUpdate) SetFps(i int) *AttachmentUpdate {
|
||||
au.mutation.ResetFps()
|
||||
au.mutation.SetFps(i)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetNillableFps sets the "fps" field if the given value is not nil.
|
||||
func (au *AttachmentUpdate) SetNillableFps(i *int) *AttachmentUpdate {
|
||||
if i != nil {
|
||||
au.SetFps(*i)
|
||||
}
|
||||
return au
|
||||
}
|
||||
|
||||
// AddFps adds i to the "fps" field.
|
||||
func (au *AttachmentUpdate) AddFps(i int) *AttachmentUpdate {
|
||||
au.mutation.AddFps(i)
|
||||
return au
|
||||
}
|
||||
|
||||
// ClearFps clears the value of the "fps" field.
|
||||
func (au *AttachmentUpdate) ClearFps() *AttachmentUpdate {
|
||||
au.mutation.ClearFps()
|
||||
return au
|
||||
}
|
||||
|
||||
// SetMimeType sets the "mimeType" field.
|
||||
func (au *AttachmentUpdate) SetMimeType(s string) *AttachmentUpdate {
|
||||
au.mutation.SetMimeType(s)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetNillableMimeType sets the "mimeType" field if the given value is not nil.
|
||||
func (au *AttachmentUpdate) SetNillableMimeType(s *string) *AttachmentUpdate {
|
||||
if s != nil {
|
||||
au.SetMimeType(*s)
|
||||
}
|
||||
return au
|
||||
}
|
||||
|
||||
// SetAuthorID sets the "author" edge to the User entity by ID.
|
||||
func (au *AttachmentUpdate) SetAuthorID(id uuid.UUID) *AttachmentUpdate {
|
||||
au.mutation.SetAuthorID(id)
|
||||
return au
|
||||
}
|
||||
|
||||
// SetAuthor sets the "author" edge to the User entity.
|
||||
func (au *AttachmentUpdate) SetAuthor(u *User) *AttachmentUpdate {
|
||||
return au.SetAuthorID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the AttachmentMutation object of the builder.
|
||||
func (au *AttachmentUpdate) Mutation() *AttachmentMutation {
|
||||
return au.mutation
|
||||
}
|
||||
|
||||
// ClearAuthor clears the "author" edge to the User entity.
|
||||
func (au *AttachmentUpdate) ClearAuthor() *AttachmentUpdate {
|
||||
au.mutation.ClearAuthor()
|
||||
return au
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (au *AttachmentUpdate) Save(ctx context.Context) (int, error) {
|
||||
au.defaults()
|
||||
return withHooks(ctx, au.sqlSave, au.mutation, au.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (au *AttachmentUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := au.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (au *AttachmentUpdate) Exec(ctx context.Context) error {
|
||||
_, err := au.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (au *AttachmentUpdate) ExecX(ctx context.Context) {
|
||||
if err := au.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (au *AttachmentUpdate) defaults() {
|
||||
if _, ok := au.mutation.UpdatedAt(); !ok {
|
||||
v := attachment.UpdateDefaultUpdatedAt()
|
||||
au.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (au *AttachmentUpdate) check() error {
|
||||
if v, ok := au.mutation.URI(); ok {
|
||||
if err := attachment.URIValidator(v); err != nil {
|
||||
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "Attachment.uri": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := au.mutation.Description(); ok {
|
||||
if err := attachment.DescriptionValidator(v); err != nil {
|
||||
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Attachment.description": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := au.mutation.AuthorID(); au.mutation.AuthorCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Attachment.author"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (au *AttachmentUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := au.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID))
|
||||
if ps := au.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := au.mutation.IsRemote(); ok {
|
||||
_spec.SetField(attachment.FieldIsRemote, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := au.mutation.URI(); ok {
|
||||
_spec.SetField(attachment.FieldURI, field.TypeString, value)
|
||||
}
|
||||
if value, ok := au.mutation.Extensions(); ok {
|
||||
_spec.SetField(attachment.FieldExtensions, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := au.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(attachment.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := au.mutation.Description(); ok {
|
||||
_spec.SetField(attachment.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if value, ok := au.mutation.Sha256(); ok {
|
||||
_spec.SetField(attachment.FieldSha256, field.TypeBytes, value)
|
||||
}
|
||||
if value, ok := au.mutation.Size(); ok {
|
||||
_spec.SetField(attachment.FieldSize, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := au.mutation.AddedSize(); ok {
|
||||
_spec.AddField(attachment.FieldSize, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := au.mutation.Blurhash(); ok {
|
||||
_spec.SetField(attachment.FieldBlurhash, field.TypeString, value)
|
||||
}
|
||||
if au.mutation.BlurhashCleared() {
|
||||
_spec.ClearField(attachment.FieldBlurhash, field.TypeString)
|
||||
}
|
||||
if value, ok := au.mutation.Height(); ok {
|
||||
_spec.SetField(attachment.FieldHeight, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := au.mutation.AddedHeight(); ok {
|
||||
_spec.AddField(attachment.FieldHeight, field.TypeInt, value)
|
||||
}
|
||||
if au.mutation.HeightCleared() {
|
||||
_spec.ClearField(attachment.FieldHeight, field.TypeInt)
|
||||
}
|
||||
if value, ok := au.mutation.Width(); ok {
|
||||
_spec.SetField(attachment.FieldWidth, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := au.mutation.AddedWidth(); ok {
|
||||
_spec.AddField(attachment.FieldWidth, field.TypeInt, value)
|
||||
}
|
||||
if au.mutation.WidthCleared() {
|
||||
_spec.ClearField(attachment.FieldWidth, field.TypeInt)
|
||||
}
|
||||
if value, ok := au.mutation.Fps(); ok {
|
||||
_spec.SetField(attachment.FieldFps, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := au.mutation.AddedFps(); ok {
|
||||
_spec.AddField(attachment.FieldFps, field.TypeInt, value)
|
||||
}
|
||||
if au.mutation.FpsCleared() {
|
||||
_spec.ClearField(attachment.FieldFps, field.TypeInt)
|
||||
}
|
||||
if value, ok := au.mutation.MimeType(); ok {
|
||||
_spec.SetField(attachment.FieldMimeType, field.TypeString, value)
|
||||
}
|
||||
if au.mutation.AuthorCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: attachment.AuthorTable,
|
||||
Columns: []string{attachment.AuthorColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := au.mutation.AuthorIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: attachment.AuthorTable,
|
||||
Columns: []string{attachment.AuthorColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{attachment.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
au.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// AttachmentUpdateOne is the builder for updating a single Attachment entity.
|
||||
type AttachmentUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *AttachmentMutation
|
||||
}
|
||||
|
||||
// SetIsRemote sets the "isRemote" field.
|
||||
func (auo *AttachmentUpdateOne) SetIsRemote(b bool) *AttachmentUpdateOne {
|
||||
auo.mutation.SetIsRemote(b)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetNillableIsRemote sets the "isRemote" field if the given value is not nil.
|
||||
func (auo *AttachmentUpdateOne) SetNillableIsRemote(b *bool) *AttachmentUpdateOne {
|
||||
if b != nil {
|
||||
auo.SetIsRemote(*b)
|
||||
}
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetURI sets the "uri" field.
|
||||
func (auo *AttachmentUpdateOne) SetURI(s string) *AttachmentUpdateOne {
|
||||
auo.mutation.SetURI(s)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetNillableURI sets the "uri" field if the given value is not nil.
|
||||
func (auo *AttachmentUpdateOne) SetNillableURI(s *string) *AttachmentUpdateOne {
|
||||
if s != nil {
|
||||
auo.SetURI(*s)
|
||||
}
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (auo *AttachmentUpdateOne) SetExtensions(l lysand.Extensions) *AttachmentUpdateOne {
|
||||
auo.mutation.SetExtensions(l)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (auo *AttachmentUpdateOne) SetUpdatedAt(t time.Time) *AttachmentUpdateOne {
|
||||
auo.mutation.SetUpdatedAt(t)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (auo *AttachmentUpdateOne) SetDescription(s string) *AttachmentUpdateOne {
|
||||
auo.mutation.SetDescription(s)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (auo *AttachmentUpdateOne) SetNillableDescription(s *string) *AttachmentUpdateOne {
|
||||
if s != nil {
|
||||
auo.SetDescription(*s)
|
||||
}
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetSha256 sets the "sha256" field.
|
||||
func (auo *AttachmentUpdateOne) SetSha256(b []byte) *AttachmentUpdateOne {
|
||||
auo.mutation.SetSha256(b)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetSize sets the "size" field.
|
||||
func (auo *AttachmentUpdateOne) SetSize(i int) *AttachmentUpdateOne {
|
||||
auo.mutation.ResetSize()
|
||||
auo.mutation.SetSize(i)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetNillableSize sets the "size" field if the given value is not nil.
|
||||
func (auo *AttachmentUpdateOne) SetNillableSize(i *int) *AttachmentUpdateOne {
|
||||
if i != nil {
|
||||
auo.SetSize(*i)
|
||||
}
|
||||
return auo
|
||||
}
|
||||
|
||||
// AddSize adds i to the "size" field.
|
||||
func (auo *AttachmentUpdateOne) AddSize(i int) *AttachmentUpdateOne {
|
||||
auo.mutation.AddSize(i)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetBlurhash sets the "blurhash" field.
|
||||
func (auo *AttachmentUpdateOne) SetBlurhash(s string) *AttachmentUpdateOne {
|
||||
auo.mutation.SetBlurhash(s)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetNillableBlurhash sets the "blurhash" field if the given value is not nil.
|
||||
func (auo *AttachmentUpdateOne) SetNillableBlurhash(s *string) *AttachmentUpdateOne {
|
||||
if s != nil {
|
||||
auo.SetBlurhash(*s)
|
||||
}
|
||||
return auo
|
||||
}
|
||||
|
||||
// ClearBlurhash clears the value of the "blurhash" field.
|
||||
func (auo *AttachmentUpdateOne) ClearBlurhash() *AttachmentUpdateOne {
|
||||
auo.mutation.ClearBlurhash()
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetHeight sets the "height" field.
|
||||
func (auo *AttachmentUpdateOne) SetHeight(i int) *AttachmentUpdateOne {
|
||||
auo.mutation.ResetHeight()
|
||||
auo.mutation.SetHeight(i)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetNillableHeight sets the "height" field if the given value is not nil.
|
||||
func (auo *AttachmentUpdateOne) SetNillableHeight(i *int) *AttachmentUpdateOne {
|
||||
if i != nil {
|
||||
auo.SetHeight(*i)
|
||||
}
|
||||
return auo
|
||||
}
|
||||
|
||||
// AddHeight adds i to the "height" field.
|
||||
func (auo *AttachmentUpdateOne) AddHeight(i int) *AttachmentUpdateOne {
|
||||
auo.mutation.AddHeight(i)
|
||||
return auo
|
||||
}
|
||||
|
||||
// ClearHeight clears the value of the "height" field.
|
||||
func (auo *AttachmentUpdateOne) ClearHeight() *AttachmentUpdateOne {
|
||||
auo.mutation.ClearHeight()
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetWidth sets the "width" field.
|
||||
func (auo *AttachmentUpdateOne) SetWidth(i int) *AttachmentUpdateOne {
|
||||
auo.mutation.ResetWidth()
|
||||
auo.mutation.SetWidth(i)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetNillableWidth sets the "width" field if the given value is not nil.
|
||||
func (auo *AttachmentUpdateOne) SetNillableWidth(i *int) *AttachmentUpdateOne {
|
||||
if i != nil {
|
||||
auo.SetWidth(*i)
|
||||
}
|
||||
return auo
|
||||
}
|
||||
|
||||
// AddWidth adds i to the "width" field.
|
||||
func (auo *AttachmentUpdateOne) AddWidth(i int) *AttachmentUpdateOne {
|
||||
auo.mutation.AddWidth(i)
|
||||
return auo
|
||||
}
|
||||
|
||||
// ClearWidth clears the value of the "width" field.
|
||||
func (auo *AttachmentUpdateOne) ClearWidth() *AttachmentUpdateOne {
|
||||
auo.mutation.ClearWidth()
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetFps sets the "fps" field.
|
||||
func (auo *AttachmentUpdateOne) SetFps(i int) *AttachmentUpdateOne {
|
||||
auo.mutation.ResetFps()
|
||||
auo.mutation.SetFps(i)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetNillableFps sets the "fps" field if the given value is not nil.
|
||||
func (auo *AttachmentUpdateOne) SetNillableFps(i *int) *AttachmentUpdateOne {
|
||||
if i != nil {
|
||||
auo.SetFps(*i)
|
||||
}
|
||||
return auo
|
||||
}
|
||||
|
||||
// AddFps adds i to the "fps" field.
|
||||
func (auo *AttachmentUpdateOne) AddFps(i int) *AttachmentUpdateOne {
|
||||
auo.mutation.AddFps(i)
|
||||
return auo
|
||||
}
|
||||
|
||||
// ClearFps clears the value of the "fps" field.
|
||||
func (auo *AttachmentUpdateOne) ClearFps() *AttachmentUpdateOne {
|
||||
auo.mutation.ClearFps()
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetMimeType sets the "mimeType" field.
|
||||
func (auo *AttachmentUpdateOne) SetMimeType(s string) *AttachmentUpdateOne {
|
||||
auo.mutation.SetMimeType(s)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetNillableMimeType sets the "mimeType" field if the given value is not nil.
|
||||
func (auo *AttachmentUpdateOne) SetNillableMimeType(s *string) *AttachmentUpdateOne {
|
||||
if s != nil {
|
||||
auo.SetMimeType(*s)
|
||||
}
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetAuthorID sets the "author" edge to the User entity by ID.
|
||||
func (auo *AttachmentUpdateOne) SetAuthorID(id uuid.UUID) *AttachmentUpdateOne {
|
||||
auo.mutation.SetAuthorID(id)
|
||||
return auo
|
||||
}
|
||||
|
||||
// SetAuthor sets the "author" edge to the User entity.
|
||||
func (auo *AttachmentUpdateOne) SetAuthor(u *User) *AttachmentUpdateOne {
|
||||
return auo.SetAuthorID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the AttachmentMutation object of the builder.
|
||||
func (auo *AttachmentUpdateOne) Mutation() *AttachmentMutation {
|
||||
return auo.mutation
|
||||
}
|
||||
|
||||
// ClearAuthor clears the "author" edge to the User entity.
|
||||
func (auo *AttachmentUpdateOne) ClearAuthor() *AttachmentUpdateOne {
|
||||
auo.mutation.ClearAuthor()
|
||||
return auo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the AttachmentUpdate builder.
|
||||
func (auo *AttachmentUpdateOne) Where(ps ...predicate.Attachment) *AttachmentUpdateOne {
|
||||
auo.mutation.Where(ps...)
|
||||
return auo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (auo *AttachmentUpdateOne) Select(field string, fields ...string) *AttachmentUpdateOne {
|
||||
auo.fields = append([]string{field}, fields...)
|
||||
return auo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Attachment entity.
|
||||
func (auo *AttachmentUpdateOne) Save(ctx context.Context) (*Attachment, error) {
|
||||
auo.defaults()
|
||||
return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (auo *AttachmentUpdateOne) SaveX(ctx context.Context) *Attachment {
|
||||
node, err := auo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (auo *AttachmentUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := auo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (auo *AttachmentUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := auo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (auo *AttachmentUpdateOne) defaults() {
|
||||
if _, ok := auo.mutation.UpdatedAt(); !ok {
|
||||
v := attachment.UpdateDefaultUpdatedAt()
|
||||
auo.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (auo *AttachmentUpdateOne) check() error {
|
||||
if v, ok := auo.mutation.URI(); ok {
|
||||
if err := attachment.URIValidator(v); err != nil {
|
||||
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "Attachment.uri": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := auo.mutation.Description(); ok {
|
||||
if err := attachment.DescriptionValidator(v); err != nil {
|
||||
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Attachment.description": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := auo.mutation.AuthorID(); auo.mutation.AuthorCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Attachment.author"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (auo *AttachmentUpdateOne) sqlSave(ctx context.Context) (_node *Attachment, err error) {
|
||||
if err := auo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID))
|
||||
id, ok := auo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Attachment.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := auo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, attachment.FieldID)
|
||||
for _, f := range fields {
|
||||
if !attachment.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != attachment.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := auo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := auo.mutation.IsRemote(); ok {
|
||||
_spec.SetField(attachment.FieldIsRemote, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := auo.mutation.URI(); ok {
|
||||
_spec.SetField(attachment.FieldURI, field.TypeString, value)
|
||||
}
|
||||
if value, ok := auo.mutation.Extensions(); ok {
|
||||
_spec.SetField(attachment.FieldExtensions, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := auo.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(attachment.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := auo.mutation.Description(); ok {
|
||||
_spec.SetField(attachment.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if value, ok := auo.mutation.Sha256(); ok {
|
||||
_spec.SetField(attachment.FieldSha256, field.TypeBytes, value)
|
||||
}
|
||||
if value, ok := auo.mutation.Size(); ok {
|
||||
_spec.SetField(attachment.FieldSize, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := auo.mutation.AddedSize(); ok {
|
||||
_spec.AddField(attachment.FieldSize, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := auo.mutation.Blurhash(); ok {
|
||||
_spec.SetField(attachment.FieldBlurhash, field.TypeString, value)
|
||||
}
|
||||
if auo.mutation.BlurhashCleared() {
|
||||
_spec.ClearField(attachment.FieldBlurhash, field.TypeString)
|
||||
}
|
||||
if value, ok := auo.mutation.Height(); ok {
|
||||
_spec.SetField(attachment.FieldHeight, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := auo.mutation.AddedHeight(); ok {
|
||||
_spec.AddField(attachment.FieldHeight, field.TypeInt, value)
|
||||
}
|
||||
if auo.mutation.HeightCleared() {
|
||||
_spec.ClearField(attachment.FieldHeight, field.TypeInt)
|
||||
}
|
||||
if value, ok := auo.mutation.Width(); ok {
|
||||
_spec.SetField(attachment.FieldWidth, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := auo.mutation.AddedWidth(); ok {
|
||||
_spec.AddField(attachment.FieldWidth, field.TypeInt, value)
|
||||
}
|
||||
if auo.mutation.WidthCleared() {
|
||||
_spec.ClearField(attachment.FieldWidth, field.TypeInt)
|
||||
}
|
||||
if value, ok := auo.mutation.Fps(); ok {
|
||||
_spec.SetField(attachment.FieldFps, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := auo.mutation.AddedFps(); ok {
|
||||
_spec.AddField(attachment.FieldFps, field.TypeInt, value)
|
||||
}
|
||||
if auo.mutation.FpsCleared() {
|
||||
_spec.ClearField(attachment.FieldFps, field.TypeInt)
|
||||
}
|
||||
if value, ok := auo.mutation.MimeType(); ok {
|
||||
_spec.SetField(attachment.FieldMimeType, field.TypeString, value)
|
||||
}
|
||||
if auo.mutation.AuthorCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: attachment.AuthorTable,
|
||||
Columns: []string{attachment.AuthorColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := auo.mutation.AuthorIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: attachment.AuthorTable,
|
||||
Columns: []string{attachment.AuthorColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Attachment{config: auo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{attachment.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
auo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
1247
ent/client.go
Normal file
1247
ent/client.go
Normal file
File diff suppressed because it is too large
Load diff
618
ent/ent.go
Normal file
618
ent/ent.go
Normal file
|
|
@ -0,0 +1,618 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/lysand-org/versia-go/ent/attachment"
|
||||
"github.com/lysand-org/versia-go/ent/follow"
|
||||
"github.com/lysand-org/versia-go/ent/image"
|
||||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/servermetadata"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
)
|
||||
|
||||
// ent aliases to avoid import conflicts in user's code.
|
||||
type (
|
||||
Op = ent.Op
|
||||
Hook = ent.Hook
|
||||
Value = ent.Value
|
||||
Query = ent.Query
|
||||
QueryContext = ent.QueryContext
|
||||
Querier = ent.Querier
|
||||
QuerierFunc = ent.QuerierFunc
|
||||
Interceptor = ent.Interceptor
|
||||
InterceptFunc = ent.InterceptFunc
|
||||
Traverser = ent.Traverser
|
||||
TraverseFunc = ent.TraverseFunc
|
||||
Policy = ent.Policy
|
||||
Mutator = ent.Mutator
|
||||
Mutation = ent.Mutation
|
||||
MutateFunc = ent.MutateFunc
|
||||
)
|
||||
|
||||
type clientCtxKey struct{}
|
||||
|
||||
// FromContext returns a Client stored inside a context, or nil if there isn't one.
|
||||
func FromContext(ctx context.Context) *Client {
|
||||
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||
return c
|
||||
}
|
||||
|
||||
// NewContext returns a new context with the given Client attached.
|
||||
func NewContext(parent context.Context, c *Client) context.Context {
|
||||
return context.WithValue(parent, clientCtxKey{}, c)
|
||||
}
|
||||
|
||||
type txCtxKey struct{}
|
||||
|
||||
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
|
||||
func TxFromContext(ctx context.Context) *Tx {
|
||||
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||
return tx
|
||||
}
|
||||
|
||||
// NewTxContext returns a new context with the given Tx attached.
|
||||
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||
return context.WithValue(parent, txCtxKey{}, tx)
|
||||
}
|
||||
|
||||
// OrderFunc applies an ordering on the sql selector.
|
||||
// Deprecated: Use Asc/Desc functions or the package builders instead.
|
||||
type OrderFunc func(*sql.Selector)
|
||||
|
||||
var (
|
||||
initCheck sync.Once
|
||||
columnCheck sql.ColumnCheck
|
||||
)
|
||||
|
||||
// columnChecker checks if the column exists in the given table.
|
||||
func checkColumn(table, column string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
attachment.Table: attachment.ValidColumn,
|
||||
follow.Table: follow.ValidColumn,
|
||||
image.Table: image.ValidColumn,
|
||||
note.Table: note.ValidColumn,
|
||||
servermetadata.Table: servermetadata.ValidColumn,
|
||||
user.Table: user.ValidColumn,
|
||||
})
|
||||
})
|
||||
return columnCheck(table, column)
|
||||
}
|
||||
|
||||
// Asc applies the given fields in ASC order.
|
||||
func Asc(fields ...string) func(*sql.Selector) {
|
||||
return func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
if err := checkColumn(s.TableName(), f); err != nil {
|
||||
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
|
||||
}
|
||||
s.OrderBy(sql.Asc(s.C(f)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Desc applies the given fields in DESC order.
|
||||
func Desc(fields ...string) func(*sql.Selector) {
|
||||
return func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
if err := checkColumn(s.TableName(), f); err != nil {
|
||||
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
|
||||
}
|
||||
s.OrderBy(sql.Desc(s.C(f)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||
type AggregateFunc func(*sql.Selector) string
|
||||
|
||||
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||
//
|
||||
// GroupBy(field1, field2).
|
||||
// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
|
||||
// Scan(ctx, &v)
|
||||
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.As(fn(s), end)
|
||||
}
|
||||
}
|
||||
|
||||
// Count applies the "count" aggregation function on each group.
|
||||
func Count() AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Count("*")
|
||||
}
|
||||
}
|
||||
|
||||
// Max applies the "max" aggregation function on the given field of each group.
|
||||
func Max(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||
return ""
|
||||
}
|
||||
return sql.Max(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||
func Mean(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||
return ""
|
||||
}
|
||||
return sql.Avg(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Min applies the "min" aggregation function on the given field of each group.
|
||||
func Min(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||
return ""
|
||||
}
|
||||
return sql.Min(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||
func Sum(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||
return ""
|
||||
}
|
||||
return sql.Sum(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// ValidationError returns when validating a field or edge fails.
|
||||
type ValidationError struct {
|
||||
Name string // Field or edge name.
|
||||
err error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *ValidationError) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ValidationError) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
// IsValidationError returns a boolean indicating whether the error is a validation error.
|
||||
func IsValidationError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ValidationError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||
type NotFoundError struct {
|
||||
label string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotFoundError) Error() string {
|
||||
return "ent: " + e.label + " not found"
|
||||
}
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// MaskNotFound masks not found error.
|
||||
func MaskNotFound(err error) error {
|
||||
if IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||
type NotSingularError struct {
|
||||
label string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotSingularError) Error() string {
|
||||
return "ent: " + e.label + " not singular"
|
||||
}
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||
type NotLoadedError struct {
|
||||
edge string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotLoadedError) Error() string {
|
||||
return "ent: " + e.edge + " edge was not loaded"
|
||||
}
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ConstraintError) Error() string {
|
||||
return "ent: constraint failed: " + e.msg
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// selector embedded by the different Select/GroupBy builders.
|
||||
type selector struct {
|
||||
label string
|
||||
flds *[]string
|
||||
fns []AggregateFunc
|
||||
scan func(context.Context, any) error
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (s *selector) ScanX(ctx context.Context, v any) {
|
||||
if err := s.scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (s *selector) StringsX(ctx context.Context) []string {
|
||||
v, err := s.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = s.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (s *selector) StringX(ctx context.Context) string {
|
||||
v, err := s.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (s *selector) IntsX(ctx context.Context) []int {
|
||||
v, err := s.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = s.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (s *selector) IntX(ctx context.Context) int {
|
||||
v, err := s.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (s *selector) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := s.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = s.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (s *selector) Float64X(ctx context.Context) float64 {
|
||||
v, err := s.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (s *selector) BoolsX(ctx context.Context) []bool {
|
||||
v, err := s.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = s.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (s *selector) BoolX(ctx context.Context) bool {
|
||||
v, err := s.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// withHooks invokes the builder operation with the given hooks, if any.
|
||||
func withHooks[V Value, M any, PM interface {
|
||||
*M
|
||||
Mutation
|
||||
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
|
||||
if len(hooks) == 0 {
|
||||
return exec(ctx)
|
||||
}
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutationT, ok := any(m).(PM)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
// Set the mutation to the builder.
|
||||
*mutation = *mutationT
|
||||
return exec(ctx)
|
||||
})
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
if hooks[i] == nil {
|
||||
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = hooks[i](mut)
|
||||
}
|
||||
v, err := mut.Mutate(ctx, mutation)
|
||||
if err != nil {
|
||||
return value, err
|
||||
}
|
||||
nv, ok := v.(V)
|
||||
if !ok {
|
||||
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
|
||||
}
|
||||
return nv, nil
|
||||
}
|
||||
|
||||
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
|
||||
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
|
||||
if ent.QueryFromContext(ctx) == nil {
|
||||
qc.Op = op
|
||||
ctx = ent.NewQueryContext(ctx, qc)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
func querierAll[V Value, Q interface {
|
||||
sqlAll(context.Context, ...queryHook) (V, error)
|
||||
}]() Querier {
|
||||
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
return query.sqlAll(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func querierCount[Q interface {
|
||||
sqlCount(context.Context) (int, error)
|
||||
}]() Querier {
|
||||
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
return query.sqlCount(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
|
||||
for i := len(inters) - 1; i >= 0; i-- {
|
||||
qr = inters[i].Intercept(qr)
|
||||
}
|
||||
rv, err := qr.Query(ctx, q)
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
vt, ok := rv.(V)
|
||||
if !ok {
|
||||
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
|
||||
}
|
||||
return vt, nil
|
||||
}
|
||||
|
||||
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
|
||||
sqlScan(context.Context, Q1, any) error
|
||||
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
|
||||
rv := reflect.ValueOf(v)
|
||||
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q1)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
|
||||
return rv.Elem().Interface(), nil
|
||||
}
|
||||
return v, nil
|
||||
})
|
||||
for i := len(inters) - 1; i >= 0; i-- {
|
||||
qr = inters[i].Intercept(qr)
|
||||
}
|
||||
vv, err := qr.Query(ctx, rootQuery)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch rv2 := reflect.ValueOf(vv); {
|
||||
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
|
||||
case rv.Type() == rv2.Type():
|
||||
rv.Elem().Set(rv2.Elem())
|
||||
case rv.Elem().Type() == rv2.Type():
|
||||
rv.Elem().Set(rv2)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// queryHook describes an internal hook for the different sqlAll methods.
|
||||
type queryHook func(context.Context, *sqlgraph.QuerySpec)
|
||||
84
ent/enttest/enttest.go
Normal file
84
ent/enttest/enttest.go
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package enttest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
// required by schema hooks.
|
||||
_ "github.com/lysand-org/versia-go/ent/runtime"
|
||||
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"github.com/lysand-org/versia-go/ent/migrate"
|
||||
)
|
||||
|
||||
type (
|
||||
// TestingT is the interface that is shared between
|
||||
// testing.T and testing.B and used by enttest.
|
||||
TestingT interface {
|
||||
FailNow()
|
||||
Error(...any)
|
||||
}
|
||||
|
||||
// Option configures client creation.
|
||||
Option func(*options)
|
||||
|
||||
options struct {
|
||||
opts []ent.Option
|
||||
migrateOpts []schema.MigrateOption
|
||||
}
|
||||
)
|
||||
|
||||
// WithOptions forwards options to client creation.
|
||||
func WithOptions(opts ...ent.Option) Option {
|
||||
return func(o *options) {
|
||||
o.opts = append(o.opts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// WithMigrateOptions forwards options to auto migration.
|
||||
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
|
||||
return func(o *options) {
|
||||
o.migrateOpts = append(o.migrateOpts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
func newOptions(opts []Option) *options {
|
||||
o := &options{}
|
||||
for _, opt := range opts {
|
||||
opt(o)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// Open calls ent.Open and auto-run migration.
|
||||
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {
|
||||
o := newOptions(opts)
|
||||
c, err := ent.Open(driverName, dataSourceName, o.opts...)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
migrateSchema(t, c, o)
|
||||
return c
|
||||
}
|
||||
|
||||
// NewClient calls ent.NewClient and auto-run migration.
|
||||
func NewClient(t TestingT, opts ...Option) *ent.Client {
|
||||
o := newOptions(opts)
|
||||
c := ent.NewClient(o.opts...)
|
||||
migrateSchema(t, c, o)
|
||||
return c
|
||||
}
|
||||
func migrateSchema(t TestingT, c *ent.Client, o *options) {
|
||||
tables, err := schema.CopyTables(migrate.Tables)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
237
ent/follow.go
Normal file
237
ent/follow.go
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/follow"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
// Follow is the model entity for the Follow schema.
|
||||
type Follow struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID uuid.UUID `json:"id,omitempty"`
|
||||
// IsRemote holds the value of the "isRemote" field.
|
||||
IsRemote bool `json:"isRemote,omitempty"`
|
||||
// URI holds the value of the "uri" field.
|
||||
URI string `json:"uri,omitempty"`
|
||||
// Extensions holds the value of the "extensions" field.
|
||||
Extensions lysand.Extensions `json:"extensions,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// Status holds the value of the "status" field.
|
||||
Status follow.Status `json:"status,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the FollowQuery when eager-loading is set.
|
||||
Edges FollowEdges `json:"edges"`
|
||||
follow_follower *uuid.UUID
|
||||
follow_followee *uuid.UUID
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// FollowEdges holds the relations/edges for other nodes in the graph.
|
||||
type FollowEdges struct {
|
||||
// Follower holds the value of the follower edge.
|
||||
Follower *User `json:"follower,omitempty"`
|
||||
// Followee holds the value of the followee edge.
|
||||
Followee *User `json:"followee,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [2]bool
|
||||
}
|
||||
|
||||
// FollowerOrErr returns the Follower value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e FollowEdges) FollowerOrErr() (*User, error) {
|
||||
if e.Follower != nil {
|
||||
return e.Follower, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "follower"}
|
||||
}
|
||||
|
||||
// FolloweeOrErr returns the Followee value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e FollowEdges) FolloweeOrErr() (*User, error) {
|
||||
if e.Followee != nil {
|
||||
return e.Followee, nil
|
||||
} else if e.loadedTypes[1] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "followee"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Follow) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case follow.FieldExtensions:
|
||||
values[i] = new([]byte)
|
||||
case follow.FieldIsRemote:
|
||||
values[i] = new(sql.NullBool)
|
||||
case follow.FieldURI, follow.FieldStatus:
|
||||
values[i] = new(sql.NullString)
|
||||
case follow.FieldCreatedAt, follow.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
case follow.FieldID:
|
||||
values[i] = new(uuid.UUID)
|
||||
case follow.ForeignKeys[0]: // follow_follower
|
||||
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
||||
case follow.ForeignKeys[1]: // follow_followee
|
||||
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Follow fields.
|
||||
func (f *Follow) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case follow.FieldID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||
} else if value != nil {
|
||||
f.ID = *value
|
||||
}
|
||||
case follow.FieldIsRemote:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field isRemote", values[i])
|
||||
} else if value.Valid {
|
||||
f.IsRemote = value.Bool
|
||||
}
|
||||
case follow.FieldURI:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uri", values[i])
|
||||
} else if value.Valid {
|
||||
f.URI = value.String
|
||||
}
|
||||
case follow.FieldExtensions:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field extensions", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &f.Extensions); err != nil {
|
||||
return fmt.Errorf("unmarshal field extensions: %w", err)
|
||||
}
|
||||
}
|
||||
case follow.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
f.CreatedAt = value.Time
|
||||
}
|
||||
case follow.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
f.UpdatedAt = value.Time
|
||||
}
|
||||
case follow.FieldStatus:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||
} else if value.Valid {
|
||||
f.Status = follow.Status(value.String)
|
||||
}
|
||||
case follow.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullScanner); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field follow_follower", values[i])
|
||||
} else if value.Valid {
|
||||
f.follow_follower = new(uuid.UUID)
|
||||
*f.follow_follower = *value.S.(*uuid.UUID)
|
||||
}
|
||||
case follow.ForeignKeys[1]:
|
||||
if value, ok := values[i].(*sql.NullScanner); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field follow_followee", values[i])
|
||||
} else if value.Valid {
|
||||
f.follow_followee = new(uuid.UUID)
|
||||
*f.follow_followee = *value.S.(*uuid.UUID)
|
||||
}
|
||||
default:
|
||||
f.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Follow.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (f *Follow) Value(name string) (ent.Value, error) {
|
||||
return f.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryFollower queries the "follower" edge of the Follow entity.
|
||||
func (f *Follow) QueryFollower() *UserQuery {
|
||||
return NewFollowClient(f.config).QueryFollower(f)
|
||||
}
|
||||
|
||||
// QueryFollowee queries the "followee" edge of the Follow entity.
|
||||
func (f *Follow) QueryFollowee() *UserQuery {
|
||||
return NewFollowClient(f.config).QueryFollowee(f)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Follow.
|
||||
// Note that you need to call Follow.Unwrap() before calling this method if this Follow
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (f *Follow) Update() *FollowUpdateOne {
|
||||
return NewFollowClient(f.config).UpdateOne(f)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Follow entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (f *Follow) Unwrap() *Follow {
|
||||
_tx, ok := f.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Follow is not a transactional entity")
|
||||
}
|
||||
f.config.driver = _tx.drv
|
||||
return f
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (f *Follow) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Follow(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", f.ID))
|
||||
builder.WriteString("isRemote=")
|
||||
builder.WriteString(fmt.Sprintf("%v", f.IsRemote))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uri=")
|
||||
builder.WriteString(f.URI)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("extensions=")
|
||||
builder.WriteString(fmt.Sprintf("%v", f.Extensions))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(f.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(f.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("status=")
|
||||
builder.WriteString(fmt.Sprintf("%v", f.Status))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Follows is a parsable slice of Follow.
|
||||
type Follows []*Follow
|
||||
187
ent/follow/follow.go
Normal file
187
ent/follow/follow.go
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package follow
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the follow type in the database.
|
||||
Label = "follow"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldIsRemote holds the string denoting the isremote field in the database.
|
||||
FieldIsRemote = "is_remote"
|
||||
// FieldURI holds the string denoting the uri field in the database.
|
||||
FieldURI = "uri"
|
||||
// FieldExtensions holds the string denoting the extensions field in the database.
|
||||
FieldExtensions = "extensions"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldStatus holds the string denoting the status field in the database.
|
||||
FieldStatus = "status"
|
||||
// EdgeFollower holds the string denoting the follower edge name in mutations.
|
||||
EdgeFollower = "follower"
|
||||
// EdgeFollowee holds the string denoting the followee edge name in mutations.
|
||||
EdgeFollowee = "followee"
|
||||
// Table holds the table name of the follow in the database.
|
||||
Table = "follows"
|
||||
// FollowerTable is the table that holds the follower relation/edge.
|
||||
FollowerTable = "follows"
|
||||
// FollowerInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
FollowerInverseTable = "users"
|
||||
// FollowerColumn is the table column denoting the follower relation/edge.
|
||||
FollowerColumn = "follow_follower"
|
||||
// FolloweeTable is the table that holds the followee relation/edge.
|
||||
FolloweeTable = "follows"
|
||||
// FolloweeInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
FolloweeInverseTable = "users"
|
||||
// FolloweeColumn is the table column denoting the followee relation/edge.
|
||||
FolloweeColumn = "follow_followee"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for follow fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldIsRemote,
|
||||
FieldURI,
|
||||
FieldExtensions,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldStatus,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "follows"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"follow_follower",
|
||||
"follow_followee",
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
URIValidator func(string) error
|
||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
||||
DefaultExtensions lysand.Extensions
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time
|
||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||
UpdateDefaultUpdatedAt func() time.Time
|
||||
// DefaultID holds the default value on creation for the "id" field.
|
||||
DefaultID func() uuid.UUID
|
||||
)
|
||||
|
||||
// Status defines the type for the "status" enum field.
|
||||
type Status string
|
||||
|
||||
// StatusPending is the default value of the Status enum.
|
||||
const DefaultStatus = StatusPending
|
||||
|
||||
// Status values.
|
||||
const (
|
||||
StatusPending Status = "pending"
|
||||
StatusAccepted Status = "accepted"
|
||||
)
|
||||
|
||||
func (s Status) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// StatusValidator is a validator for the "status" field enum values. It is called by the builders before save.
|
||||
func StatusValidator(s Status) error {
|
||||
switch s {
|
||||
case StatusPending, StatusAccepted:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("follow: invalid enum value for status field: %q", s)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the Follow queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByIsRemote orders the results by the isRemote field.
|
||||
func ByIsRemote(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldIsRemote, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByURI orders the results by the uri field.
|
||||
func ByURI(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldURI, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByStatus orders the results by the status field.
|
||||
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByFollowerField orders the results by follower field.
|
||||
func ByFollowerField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newFollowerStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByFolloweeField orders the results by followee field.
|
||||
func ByFolloweeField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newFolloweeStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newFollowerStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(FollowerInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, FollowerTable, FollowerColumn),
|
||||
)
|
||||
}
|
||||
func newFolloweeStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(FolloweeInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, FolloweeTable, FolloweeColumn),
|
||||
)
|
||||
}
|
||||
313
ent/follow/where.go
Normal file
313
ent/follow/where.go
Normal file
|
|
@ -0,0 +1,313 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package follow
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id uuid.UUID) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id uuid.UUID) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id uuid.UUID) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...uuid.UUID) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...uuid.UUID) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id uuid.UUID) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id uuid.UUID) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id uuid.UUID) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id uuid.UUID) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IsRemote applies equality check predicate on the "isRemote" field. It's identical to IsRemoteEQ.
|
||||
func IsRemote(v bool) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldEQ(FieldIsRemote, v))
|
||||
}
|
||||
|
||||
// URI applies equality check predicate on the "uri" field. It's identical to URIEQ.
|
||||
func URI(v string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldEQ(FieldURI, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// IsRemoteEQ applies the EQ predicate on the "isRemote" field.
|
||||
func IsRemoteEQ(v bool) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldEQ(FieldIsRemote, v))
|
||||
}
|
||||
|
||||
// IsRemoteNEQ applies the NEQ predicate on the "isRemote" field.
|
||||
func IsRemoteNEQ(v bool) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldNEQ(FieldIsRemote, v))
|
||||
}
|
||||
|
||||
// URIEQ applies the EQ predicate on the "uri" field.
|
||||
func URIEQ(v string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldEQ(FieldURI, v))
|
||||
}
|
||||
|
||||
// URINEQ applies the NEQ predicate on the "uri" field.
|
||||
func URINEQ(v string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldNEQ(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIIn applies the In predicate on the "uri" field.
|
||||
func URIIn(vs ...string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldIn(FieldURI, vs...))
|
||||
}
|
||||
|
||||
// URINotIn applies the NotIn predicate on the "uri" field.
|
||||
func URINotIn(vs ...string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldNotIn(FieldURI, vs...))
|
||||
}
|
||||
|
||||
// URIGT applies the GT predicate on the "uri" field.
|
||||
func URIGT(v string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldGT(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIGTE applies the GTE predicate on the "uri" field.
|
||||
func URIGTE(v string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldGTE(FieldURI, v))
|
||||
}
|
||||
|
||||
// URILT applies the LT predicate on the "uri" field.
|
||||
func URILT(v string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldLT(FieldURI, v))
|
||||
}
|
||||
|
||||
// URILTE applies the LTE predicate on the "uri" field.
|
||||
func URILTE(v string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldLTE(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIContains applies the Contains predicate on the "uri" field.
|
||||
func URIContains(v string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldContains(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIHasPrefix applies the HasPrefix predicate on the "uri" field.
|
||||
func URIHasPrefix(v string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldHasPrefix(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIHasSuffix applies the HasSuffix predicate on the "uri" field.
|
||||
func URIHasSuffix(v string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldHasSuffix(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIEqualFold applies the EqualFold predicate on the "uri" field.
|
||||
func URIEqualFold(v string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldEqualFold(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIContainsFold applies the ContainsFold predicate on the "uri" field.
|
||||
func URIContainsFold(v string) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldContainsFold(FieldURI, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldGT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldGTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldLT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// StatusEQ applies the EQ predicate on the "status" field.
|
||||
func StatusEQ(v Status) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusNEQ applies the NEQ predicate on the "status" field.
|
||||
func StatusNEQ(v Status) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldNEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusIn applies the In predicate on the "status" field.
|
||||
func StatusIn(vs ...Status) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// StatusNotIn applies the NotIn predicate on the "status" field.
|
||||
func StatusNotIn(vs ...Status) predicate.Follow {
|
||||
return predicate.Follow(sql.FieldNotIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// HasFollower applies the HasEdge predicate on the "follower" edge.
|
||||
func HasFollower() predicate.Follow {
|
||||
return predicate.Follow(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, FollowerTable, FollowerColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasFollowerWith applies the HasEdge predicate on the "follower" edge with a given conditions (other predicates).
|
||||
func HasFollowerWith(preds ...predicate.User) predicate.Follow {
|
||||
return predicate.Follow(func(s *sql.Selector) {
|
||||
step := newFollowerStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasFollowee applies the HasEdge predicate on the "followee" edge.
|
||||
func HasFollowee() predicate.Follow {
|
||||
return predicate.Follow(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, FolloweeTable, FolloweeColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasFolloweeWith applies the HasEdge predicate on the "followee" edge with a given conditions (other predicates).
|
||||
func HasFolloweeWith(preds ...predicate.User) predicate.Follow {
|
||||
return predicate.Follow(func(s *sql.Selector) {
|
||||
step := newFolloweeStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Follow) predicate.Follow {
|
||||
return predicate.Follow(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Follow) predicate.Follow {
|
||||
return predicate.Follow(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Follow) predicate.Follow {
|
||||
return predicate.Follow(sql.NotPredicates(p))
|
||||
}
|
||||
854
ent/follow_create.go
Normal file
854
ent/follow_create.go
Normal file
|
|
@ -0,0 +1,854 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/follow"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
// FollowCreate is the builder for creating a Follow entity.
|
||||
type FollowCreate struct {
|
||||
config
|
||||
mutation *FollowMutation
|
||||
hooks []Hook
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// SetIsRemote sets the "isRemote" field.
|
||||
func (fc *FollowCreate) SetIsRemote(b bool) *FollowCreate {
|
||||
fc.mutation.SetIsRemote(b)
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetURI sets the "uri" field.
|
||||
func (fc *FollowCreate) SetURI(s string) *FollowCreate {
|
||||
fc.mutation.SetURI(s)
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (fc *FollowCreate) SetExtensions(l lysand.Extensions) *FollowCreate {
|
||||
fc.mutation.SetExtensions(l)
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (fc *FollowCreate) SetCreatedAt(t time.Time) *FollowCreate {
|
||||
fc.mutation.SetCreatedAt(t)
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (fc *FollowCreate) SetNillableCreatedAt(t *time.Time) *FollowCreate {
|
||||
if t != nil {
|
||||
fc.SetCreatedAt(*t)
|
||||
}
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (fc *FollowCreate) SetUpdatedAt(t time.Time) *FollowCreate {
|
||||
fc.mutation.SetUpdatedAt(t)
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (fc *FollowCreate) SetNillableUpdatedAt(t *time.Time) *FollowCreate {
|
||||
if t != nil {
|
||||
fc.SetUpdatedAt(*t)
|
||||
}
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (fc *FollowCreate) SetStatus(f follow.Status) *FollowCreate {
|
||||
fc.mutation.SetStatus(f)
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (fc *FollowCreate) SetNillableStatus(f *follow.Status) *FollowCreate {
|
||||
if f != nil {
|
||||
fc.SetStatus(*f)
|
||||
}
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (fc *FollowCreate) SetID(u uuid.UUID) *FollowCreate {
|
||||
fc.mutation.SetID(u)
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetNillableID sets the "id" field if the given value is not nil.
|
||||
func (fc *FollowCreate) SetNillableID(u *uuid.UUID) *FollowCreate {
|
||||
if u != nil {
|
||||
fc.SetID(*u)
|
||||
}
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetFollowerID sets the "follower" edge to the User entity by ID.
|
||||
func (fc *FollowCreate) SetFollowerID(id uuid.UUID) *FollowCreate {
|
||||
fc.mutation.SetFollowerID(id)
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetFollower sets the "follower" edge to the User entity.
|
||||
func (fc *FollowCreate) SetFollower(u *User) *FollowCreate {
|
||||
return fc.SetFollowerID(u.ID)
|
||||
}
|
||||
|
||||
// SetFolloweeID sets the "followee" edge to the User entity by ID.
|
||||
func (fc *FollowCreate) SetFolloweeID(id uuid.UUID) *FollowCreate {
|
||||
fc.mutation.SetFolloweeID(id)
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetFollowee sets the "followee" edge to the User entity.
|
||||
func (fc *FollowCreate) SetFollowee(u *User) *FollowCreate {
|
||||
return fc.SetFolloweeID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the FollowMutation object of the builder.
|
||||
func (fc *FollowCreate) Mutation() *FollowMutation {
|
||||
return fc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Follow in the database.
|
||||
func (fc *FollowCreate) Save(ctx context.Context) (*Follow, error) {
|
||||
fc.defaults()
|
||||
return withHooks(ctx, fc.sqlSave, fc.mutation, fc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (fc *FollowCreate) SaveX(ctx context.Context) *Follow {
|
||||
v, err := fc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (fc *FollowCreate) Exec(ctx context.Context) error {
|
||||
_, err := fc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (fc *FollowCreate) ExecX(ctx context.Context) {
|
||||
if err := fc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (fc *FollowCreate) defaults() {
|
||||
if _, ok := fc.mutation.Extensions(); !ok {
|
||||
v := follow.DefaultExtensions
|
||||
fc.mutation.SetExtensions(v)
|
||||
}
|
||||
if _, ok := fc.mutation.CreatedAt(); !ok {
|
||||
v := follow.DefaultCreatedAt()
|
||||
fc.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := fc.mutation.UpdatedAt(); !ok {
|
||||
v := follow.DefaultUpdatedAt()
|
||||
fc.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
if _, ok := fc.mutation.Status(); !ok {
|
||||
v := follow.DefaultStatus
|
||||
fc.mutation.SetStatus(v)
|
||||
}
|
||||
if _, ok := fc.mutation.ID(); !ok {
|
||||
v := follow.DefaultID()
|
||||
fc.mutation.SetID(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (fc *FollowCreate) check() error {
|
||||
if _, ok := fc.mutation.IsRemote(); !ok {
|
||||
return &ValidationError{Name: "isRemote", err: errors.New(`ent: missing required field "Follow.isRemote"`)}
|
||||
}
|
||||
if _, ok := fc.mutation.URI(); !ok {
|
||||
return &ValidationError{Name: "uri", err: errors.New(`ent: missing required field "Follow.uri"`)}
|
||||
}
|
||||
if v, ok := fc.mutation.URI(); ok {
|
||||
if err := follow.URIValidator(v); err != nil {
|
||||
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "Follow.uri": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := fc.mutation.Extensions(); !ok {
|
||||
return &ValidationError{Name: "extensions", err: errors.New(`ent: missing required field "Follow.extensions"`)}
|
||||
}
|
||||
if _, ok := fc.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Follow.created_at"`)}
|
||||
}
|
||||
if _, ok := fc.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Follow.updated_at"`)}
|
||||
}
|
||||
if _, ok := fc.mutation.Status(); !ok {
|
||||
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Follow.status"`)}
|
||||
}
|
||||
if v, ok := fc.mutation.Status(); ok {
|
||||
if err := follow.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Follow.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := fc.mutation.FollowerID(); !ok {
|
||||
return &ValidationError{Name: "follower", err: errors.New(`ent: missing required edge "Follow.follower"`)}
|
||||
}
|
||||
if _, ok := fc.mutation.FolloweeID(); !ok {
|
||||
return &ValidationError{Name: "followee", err: errors.New(`ent: missing required edge "Follow.followee"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fc *FollowCreate) sqlSave(ctx context.Context) (*Follow, error) {
|
||||
if err := fc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := fc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, fc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if _spec.ID.Value != nil {
|
||||
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
||||
_node.ID = *id
|
||||
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
fc.mutation.id = &_node.ID
|
||||
fc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (fc *FollowCreate) createSpec() (*Follow, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Follow{config: fc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(follow.Table, sqlgraph.NewFieldSpec(follow.FieldID, field.TypeUUID))
|
||||
)
|
||||
_spec.OnConflict = fc.conflict
|
||||
if id, ok := fc.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := fc.mutation.IsRemote(); ok {
|
||||
_spec.SetField(follow.FieldIsRemote, field.TypeBool, value)
|
||||
_node.IsRemote = value
|
||||
}
|
||||
if value, ok := fc.mutation.URI(); ok {
|
||||
_spec.SetField(follow.FieldURI, field.TypeString, value)
|
||||
_node.URI = value
|
||||
}
|
||||
if value, ok := fc.mutation.Extensions(); ok {
|
||||
_spec.SetField(follow.FieldExtensions, field.TypeJSON, value)
|
||||
_node.Extensions = value
|
||||
}
|
||||
if value, ok := fc.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(follow.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := fc.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(follow.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := fc.mutation.Status(); ok {
|
||||
_spec.SetField(follow.FieldStatus, field.TypeEnum, value)
|
||||
_node.Status = value
|
||||
}
|
||||
if nodes := fc.mutation.FollowerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: follow.FollowerTable,
|
||||
Columns: []string{follow.FollowerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.follow_follower = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := fc.mutation.FolloweeIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: follow.FolloweeTable,
|
||||
Columns: []string{follow.FolloweeColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.follow_followee = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.Follow.Create().
|
||||
// SetIsRemote(v).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.FollowUpsert) {
|
||||
// SetIsRemote(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (fc *FollowCreate) OnConflict(opts ...sql.ConflictOption) *FollowUpsertOne {
|
||||
fc.conflict = opts
|
||||
return &FollowUpsertOne{
|
||||
create: fc,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.Follow.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (fc *FollowCreate) OnConflictColumns(columns ...string) *FollowUpsertOne {
|
||||
fc.conflict = append(fc.conflict, sql.ConflictColumns(columns...))
|
||||
return &FollowUpsertOne{
|
||||
create: fc,
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
// FollowUpsertOne is the builder for "upsert"-ing
|
||||
// one Follow node.
|
||||
FollowUpsertOne struct {
|
||||
create *FollowCreate
|
||||
}
|
||||
|
||||
// FollowUpsert is the "OnConflict" setter.
|
||||
FollowUpsert struct {
|
||||
*sql.UpdateSet
|
||||
}
|
||||
)
|
||||
|
||||
// SetIsRemote sets the "isRemote" field.
|
||||
func (u *FollowUpsert) SetIsRemote(v bool) *FollowUpsert {
|
||||
u.Set(follow.FieldIsRemote, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateIsRemote sets the "isRemote" field to the value that was provided on create.
|
||||
func (u *FollowUpsert) UpdateIsRemote() *FollowUpsert {
|
||||
u.SetExcluded(follow.FieldIsRemote)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetURI sets the "uri" field.
|
||||
func (u *FollowUpsert) SetURI(v string) *FollowUpsert {
|
||||
u.Set(follow.FieldURI, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateURI sets the "uri" field to the value that was provided on create.
|
||||
func (u *FollowUpsert) UpdateURI() *FollowUpsert {
|
||||
u.SetExcluded(follow.FieldURI)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *FollowUpsert) SetExtensions(v lysand.Extensions) *FollowUpsert {
|
||||
u.Set(follow.FieldExtensions, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateExtensions sets the "extensions" field to the value that was provided on create.
|
||||
func (u *FollowUpsert) UpdateExtensions() *FollowUpsert {
|
||||
u.SetExcluded(follow.FieldExtensions)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (u *FollowUpsert) SetUpdatedAt(v time.Time) *FollowUpsert {
|
||||
u.Set(follow.FieldUpdatedAt, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||
func (u *FollowUpsert) UpdateUpdatedAt() *FollowUpsert {
|
||||
u.SetExcluded(follow.FieldUpdatedAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (u *FollowUpsert) SetStatus(v follow.Status) *FollowUpsert {
|
||||
u.Set(follow.FieldStatus, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateStatus sets the "status" field to the value that was provided on create.
|
||||
func (u *FollowUpsert) UpdateStatus() *FollowUpsert {
|
||||
u.SetExcluded(follow.FieldStatus)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.Follow.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
||||
// u.SetIgnore(follow.FieldID)
|
||||
// }),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *FollowUpsertOne) UpdateNewValues() *FollowUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
if _, exists := u.create.mutation.ID(); exists {
|
||||
s.SetIgnore(follow.FieldID)
|
||||
}
|
||||
if _, exists := u.create.mutation.CreatedAt(); exists {
|
||||
s.SetIgnore(follow.FieldCreatedAt)
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.Follow.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *FollowUpsertOne) Ignore() *FollowUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *FollowUpsertOne) DoNothing() *FollowUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the FollowCreate.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *FollowUpsertOne) Update(set func(*FollowUpsert)) *FollowUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&FollowUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetIsRemote sets the "isRemote" field.
|
||||
func (u *FollowUpsertOne) SetIsRemote(v bool) *FollowUpsertOne {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.SetIsRemote(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateIsRemote sets the "isRemote" field to the value that was provided on create.
|
||||
func (u *FollowUpsertOne) UpdateIsRemote() *FollowUpsertOne {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.UpdateIsRemote()
|
||||
})
|
||||
}
|
||||
|
||||
// SetURI sets the "uri" field.
|
||||
func (u *FollowUpsertOne) SetURI(v string) *FollowUpsertOne {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.SetURI(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateURI sets the "uri" field to the value that was provided on create.
|
||||
func (u *FollowUpsertOne) UpdateURI() *FollowUpsertOne {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.UpdateURI()
|
||||
})
|
||||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *FollowUpsertOne) SetExtensions(v lysand.Extensions) *FollowUpsertOne {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.SetExtensions(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateExtensions sets the "extensions" field to the value that was provided on create.
|
||||
func (u *FollowUpsertOne) UpdateExtensions() *FollowUpsertOne {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.UpdateExtensions()
|
||||
})
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (u *FollowUpsertOne) SetUpdatedAt(v time.Time) *FollowUpsertOne {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.SetUpdatedAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||
func (u *FollowUpsertOne) UpdateUpdatedAt() *FollowUpsertOne {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.UpdateUpdatedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (u *FollowUpsertOne) SetStatus(v follow.Status) *FollowUpsertOne {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.SetStatus(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateStatus sets the "status" field to the value that was provided on create.
|
||||
func (u *FollowUpsertOne) UpdateStatus() *FollowUpsertOne {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.UpdateStatus()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *FollowUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for FollowCreate.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *FollowUpsertOne) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
||||
func (u *FollowUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
if u.create.driver.Dialect() == dialect.MySQL {
|
||||
// In case of "ON CONFLICT", there is no way to get back non-numeric ID
|
||||
// fields from the database since MySQL does not support the RETURNING clause.
|
||||
return id, errors.New("ent: FollowUpsertOne.ID is not supported by MySQL driver. Use FollowUpsertOne.Exec instead")
|
||||
}
|
||||
node, err := u.create.Save(ctx)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
return node.ID, nil
|
||||
}
|
||||
|
||||
// IDX is like ID, but panics if an error occurs.
|
||||
func (u *FollowUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
||||
id, err := u.ID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// FollowCreateBulk is the builder for creating many Follow entities in bulk.
|
||||
type FollowCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*FollowCreate
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// Save creates the Follow entities in the database.
|
||||
func (fcb *FollowCreateBulk) Save(ctx context.Context) ([]*Follow, error) {
|
||||
if fcb.err != nil {
|
||||
return nil, fcb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(fcb.builders))
|
||||
nodes := make([]*Follow, len(fcb.builders))
|
||||
mutators := make([]Mutator, len(fcb.builders))
|
||||
for i := range fcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := fcb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*FollowMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, fcb.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
spec.OnConflict = fcb.conflict
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, fcb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, fcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (fcb *FollowCreateBulk) SaveX(ctx context.Context) []*Follow {
|
||||
v, err := fcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (fcb *FollowCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := fcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (fcb *FollowCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := fcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.Follow.CreateBulk(builders...).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.FollowUpsert) {
|
||||
// SetIsRemote(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (fcb *FollowCreateBulk) OnConflict(opts ...sql.ConflictOption) *FollowUpsertBulk {
|
||||
fcb.conflict = opts
|
||||
return &FollowUpsertBulk{
|
||||
create: fcb,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.Follow.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (fcb *FollowCreateBulk) OnConflictColumns(columns ...string) *FollowUpsertBulk {
|
||||
fcb.conflict = append(fcb.conflict, sql.ConflictColumns(columns...))
|
||||
return &FollowUpsertBulk{
|
||||
create: fcb,
|
||||
}
|
||||
}
|
||||
|
||||
// FollowUpsertBulk is the builder for "upsert"-ing
|
||||
// a bulk of Follow nodes.
|
||||
type FollowUpsertBulk struct {
|
||||
create *FollowCreateBulk
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that
|
||||
// were set on create. Using this option is equivalent to using:
|
||||
//
|
||||
// client.Follow.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
||||
// u.SetIgnore(follow.FieldID)
|
||||
// }),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *FollowUpsertBulk) UpdateNewValues() *FollowUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
for _, b := range u.create.builders {
|
||||
if _, exists := b.mutation.ID(); exists {
|
||||
s.SetIgnore(follow.FieldID)
|
||||
}
|
||||
if _, exists := b.mutation.CreatedAt(); exists {
|
||||
s.SetIgnore(follow.FieldCreatedAt)
|
||||
}
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.Follow.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *FollowUpsertBulk) Ignore() *FollowUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *FollowUpsertBulk) DoNothing() *FollowUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the FollowCreateBulk.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *FollowUpsertBulk) Update(set func(*FollowUpsert)) *FollowUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&FollowUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetIsRemote sets the "isRemote" field.
|
||||
func (u *FollowUpsertBulk) SetIsRemote(v bool) *FollowUpsertBulk {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.SetIsRemote(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateIsRemote sets the "isRemote" field to the value that was provided on create.
|
||||
func (u *FollowUpsertBulk) UpdateIsRemote() *FollowUpsertBulk {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.UpdateIsRemote()
|
||||
})
|
||||
}
|
||||
|
||||
// SetURI sets the "uri" field.
|
||||
func (u *FollowUpsertBulk) SetURI(v string) *FollowUpsertBulk {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.SetURI(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateURI sets the "uri" field to the value that was provided on create.
|
||||
func (u *FollowUpsertBulk) UpdateURI() *FollowUpsertBulk {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.UpdateURI()
|
||||
})
|
||||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *FollowUpsertBulk) SetExtensions(v lysand.Extensions) *FollowUpsertBulk {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.SetExtensions(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateExtensions sets the "extensions" field to the value that was provided on create.
|
||||
func (u *FollowUpsertBulk) UpdateExtensions() *FollowUpsertBulk {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.UpdateExtensions()
|
||||
})
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (u *FollowUpsertBulk) SetUpdatedAt(v time.Time) *FollowUpsertBulk {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.SetUpdatedAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||
func (u *FollowUpsertBulk) UpdateUpdatedAt() *FollowUpsertBulk {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.UpdateUpdatedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (u *FollowUpsertBulk) SetStatus(v follow.Status) *FollowUpsertBulk {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.SetStatus(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateStatus sets the "status" field to the value that was provided on create.
|
||||
func (u *FollowUpsertBulk) UpdateStatus() *FollowUpsertBulk {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.UpdateStatus()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *FollowUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
return u.create.err
|
||||
}
|
||||
for i, b := range u.create.builders {
|
||||
if len(b.conflict) != 0 {
|
||||
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the FollowCreateBulk instead", i)
|
||||
}
|
||||
}
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for FollowCreateBulk.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *FollowUpsertBulk) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
88
ent/follow_delete.go
Normal file
88
ent/follow_delete.go
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/lysand-org/versia-go/ent/follow"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
)
|
||||
|
||||
// FollowDelete is the builder for deleting a Follow entity.
|
||||
type FollowDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *FollowMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the FollowDelete builder.
|
||||
func (fd *FollowDelete) Where(ps ...predicate.Follow) *FollowDelete {
|
||||
fd.mutation.Where(ps...)
|
||||
return fd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (fd *FollowDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, fd.sqlExec, fd.mutation, fd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (fd *FollowDelete) ExecX(ctx context.Context) int {
|
||||
n, err := fd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (fd *FollowDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(follow.Table, sqlgraph.NewFieldSpec(follow.FieldID, field.TypeUUID))
|
||||
if ps := fd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, fd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
fd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// FollowDeleteOne is the builder for deleting a single Follow entity.
|
||||
type FollowDeleteOne struct {
|
||||
fd *FollowDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the FollowDelete builder.
|
||||
func (fdo *FollowDeleteOne) Where(ps ...predicate.Follow) *FollowDeleteOne {
|
||||
fdo.fd.mutation.Where(ps...)
|
||||
return fdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (fdo *FollowDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := fdo.fd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{follow.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (fdo *FollowDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := fdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
688
ent/follow_query.go
Normal file
688
ent/follow_query.go
Normal file
|
|
@ -0,0 +1,688 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/follow"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
)
|
||||
|
||||
// FollowQuery is the builder for querying Follow entities.
|
||||
type FollowQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []follow.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Follow
|
||||
withFollower *UserQuery
|
||||
withFollowee *UserQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the FollowQuery builder.
|
||||
func (fq *FollowQuery) Where(ps ...predicate.Follow) *FollowQuery {
|
||||
fq.predicates = append(fq.predicates, ps...)
|
||||
return fq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (fq *FollowQuery) Limit(limit int) *FollowQuery {
|
||||
fq.ctx.Limit = &limit
|
||||
return fq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (fq *FollowQuery) Offset(offset int) *FollowQuery {
|
||||
fq.ctx.Offset = &offset
|
||||
return fq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (fq *FollowQuery) Unique(unique bool) *FollowQuery {
|
||||
fq.ctx.Unique = &unique
|
||||
return fq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (fq *FollowQuery) Order(o ...follow.OrderOption) *FollowQuery {
|
||||
fq.order = append(fq.order, o...)
|
||||
return fq
|
||||
}
|
||||
|
||||
// QueryFollower chains the current query on the "follower" edge.
|
||||
func (fq *FollowQuery) QueryFollower() *UserQuery {
|
||||
query := (&UserClient{config: fq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := fq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := fq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(follow.Table, follow.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, follow.FollowerTable, follow.FollowerColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(fq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryFollowee chains the current query on the "followee" edge.
|
||||
func (fq *FollowQuery) QueryFollowee() *UserQuery {
|
||||
query := (&UserClient{config: fq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := fq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := fq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(follow.Table, follow.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, follow.FolloweeTable, follow.FolloweeColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(fq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Follow entity from the query.
|
||||
// Returns a *NotFoundError when no Follow was found.
|
||||
func (fq *FollowQuery) First(ctx context.Context) (*Follow, error) {
|
||||
nodes, err := fq.Limit(1).All(setContextOp(ctx, fq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{follow.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (fq *FollowQuery) FirstX(ctx context.Context) *Follow {
|
||||
node, err := fq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Follow ID from the query.
|
||||
// Returns a *NotFoundError when no Follow ID was found.
|
||||
func (fq *FollowQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = fq.Limit(1).IDs(setContextOp(ctx, fq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{follow.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (fq *FollowQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := fq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Follow entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Follow entity is found.
|
||||
// Returns a *NotFoundError when no Follow entities are found.
|
||||
func (fq *FollowQuery) Only(ctx context.Context) (*Follow, error) {
|
||||
nodes, err := fq.Limit(2).All(setContextOp(ctx, fq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{follow.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{follow.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (fq *FollowQuery) OnlyX(ctx context.Context) *Follow {
|
||||
node, err := fq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Follow ID in the query.
|
||||
// Returns a *NotSingularError when more than one Follow ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (fq *FollowQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = fq.Limit(2).IDs(setContextOp(ctx, fq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{follow.Label}
|
||||
default:
|
||||
err = &NotSingularError{follow.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (fq *FollowQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := fq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Follows.
|
||||
func (fq *FollowQuery) All(ctx context.Context) ([]*Follow, error) {
|
||||
ctx = setContextOp(ctx, fq.ctx, "All")
|
||||
if err := fq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Follow, *FollowQuery]()
|
||||
return withInterceptors[[]*Follow](ctx, fq, qr, fq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (fq *FollowQuery) AllX(ctx context.Context) []*Follow {
|
||||
nodes, err := fq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Follow IDs.
|
||||
func (fq *FollowQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||
if fq.ctx.Unique == nil && fq.path != nil {
|
||||
fq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, fq.ctx, "IDs")
|
||||
if err = fq.Select(follow.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (fq *FollowQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||
ids, err := fq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (fq *FollowQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, fq.ctx, "Count")
|
||||
if err := fq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, fq, querierCount[*FollowQuery](), fq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (fq *FollowQuery) CountX(ctx context.Context) int {
|
||||
count, err := fq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (fq *FollowQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, fq.ctx, "Exist")
|
||||
switch _, err := fq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (fq *FollowQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := fq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the FollowQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (fq *FollowQuery) Clone() *FollowQuery {
|
||||
if fq == nil {
|
||||
return nil
|
||||
}
|
||||
return &FollowQuery{
|
||||
config: fq.config,
|
||||
ctx: fq.ctx.Clone(),
|
||||
order: append([]follow.OrderOption{}, fq.order...),
|
||||
inters: append([]Interceptor{}, fq.inters...),
|
||||
predicates: append([]predicate.Follow{}, fq.predicates...),
|
||||
withFollower: fq.withFollower.Clone(),
|
||||
withFollowee: fq.withFollowee.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: fq.sql.Clone(),
|
||||
path: fq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithFollower tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "follower" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (fq *FollowQuery) WithFollower(opts ...func(*UserQuery)) *FollowQuery {
|
||||
query := (&UserClient{config: fq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
fq.withFollower = query
|
||||
return fq
|
||||
}
|
||||
|
||||
// WithFollowee tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "followee" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (fq *FollowQuery) WithFollowee(opts ...func(*UserQuery)) *FollowQuery {
|
||||
query := (&UserClient{config: fq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
fq.withFollowee = query
|
||||
return fq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// IsRemote bool `json:"isRemote,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Follow.Query().
|
||||
// GroupBy(follow.FieldIsRemote).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (fq *FollowQuery) GroupBy(field string, fields ...string) *FollowGroupBy {
|
||||
fq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &FollowGroupBy{build: fq}
|
||||
grbuild.flds = &fq.ctx.Fields
|
||||
grbuild.label = follow.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// IsRemote bool `json:"isRemote,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Follow.Query().
|
||||
// Select(follow.FieldIsRemote).
|
||||
// Scan(ctx, &v)
|
||||
func (fq *FollowQuery) Select(fields ...string) *FollowSelect {
|
||||
fq.ctx.Fields = append(fq.ctx.Fields, fields...)
|
||||
sbuild := &FollowSelect{FollowQuery: fq}
|
||||
sbuild.label = follow.Label
|
||||
sbuild.flds, sbuild.scan = &fq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a FollowSelect configured with the given aggregations.
|
||||
func (fq *FollowQuery) Aggregate(fns ...AggregateFunc) *FollowSelect {
|
||||
return fq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (fq *FollowQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range fq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, fq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range fq.ctx.Fields {
|
||||
if !follow.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if fq.path != nil {
|
||||
prev, err := fq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fq *FollowQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Follow, error) {
|
||||
var (
|
||||
nodes = []*Follow{}
|
||||
withFKs = fq.withFKs
|
||||
_spec = fq.querySpec()
|
||||
loadedTypes = [2]bool{
|
||||
fq.withFollower != nil,
|
||||
fq.withFollowee != nil,
|
||||
}
|
||||
)
|
||||
if fq.withFollower != nil || fq.withFollowee != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, follow.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Follow).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Follow{config: fq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, fq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := fq.withFollower; query != nil {
|
||||
if err := fq.loadFollower(ctx, query, nodes, nil,
|
||||
func(n *Follow, e *User) { n.Edges.Follower = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := fq.withFollowee; query != nil {
|
||||
if err := fq.loadFollowee(ctx, query, nodes, nil,
|
||||
func(n *Follow, e *User) { n.Edges.Followee = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (fq *FollowQuery) loadFollower(ctx context.Context, query *UserQuery, nodes []*Follow, init func(*Follow), assign func(*Follow, *User)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*Follow)
|
||||
for i := range nodes {
|
||||
if nodes[i].follow_follower == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].follow_follower
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "follow_follower" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (fq *FollowQuery) loadFollowee(ctx context.Context, query *UserQuery, nodes []*Follow, init func(*Follow), assign func(*Follow, *User)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*Follow)
|
||||
for i := range nodes {
|
||||
if nodes[i].follow_followee == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].follow_followee
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "follow_followee" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fq *FollowQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := fq.querySpec()
|
||||
_spec.Node.Columns = fq.ctx.Fields
|
||||
if len(fq.ctx.Fields) > 0 {
|
||||
_spec.Unique = fq.ctx.Unique != nil && *fq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, fq.driver, _spec)
|
||||
}
|
||||
|
||||
func (fq *FollowQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(follow.Table, follow.Columns, sqlgraph.NewFieldSpec(follow.FieldID, field.TypeUUID))
|
||||
_spec.From = fq.sql
|
||||
if unique := fq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if fq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := fq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, follow.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != follow.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := fq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := fq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := fq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := fq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (fq *FollowQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(fq.driver.Dialect())
|
||||
t1 := builder.Table(follow.Table)
|
||||
columns := fq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = follow.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if fq.sql != nil {
|
||||
selector = fq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if fq.ctx.Unique != nil && *fq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range fq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range fq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := fq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := fq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// FollowGroupBy is the group-by builder for Follow entities.
|
||||
type FollowGroupBy struct {
|
||||
selector
|
||||
build *FollowQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (fgb *FollowGroupBy) Aggregate(fns ...AggregateFunc) *FollowGroupBy {
|
||||
fgb.fns = append(fgb.fns, fns...)
|
||||
return fgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (fgb *FollowGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, fgb.build.ctx, "GroupBy")
|
||||
if err := fgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*FollowQuery, *FollowGroupBy](ctx, fgb.build, fgb, fgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (fgb *FollowGroupBy) sqlScan(ctx context.Context, root *FollowQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(fgb.fns))
|
||||
for _, fn := range fgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*fgb.flds)+len(fgb.fns))
|
||||
for _, f := range *fgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*fgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := fgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// FollowSelect is the builder for selecting fields of Follow entities.
|
||||
type FollowSelect struct {
|
||||
*FollowQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (fs *FollowSelect) Aggregate(fns ...AggregateFunc) *FollowSelect {
|
||||
fs.fns = append(fs.fns, fns...)
|
||||
return fs
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (fs *FollowSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, fs.ctx, "Select")
|
||||
if err := fs.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*FollowQuery, *FollowSelect](ctx, fs.FollowQuery, fs, fs.inters, v)
|
||||
}
|
||||
|
||||
func (fs *FollowSelect) sqlScan(ctx context.Context, root *FollowQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(fs.fns))
|
||||
for _, fn := range fs.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*fs.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := fs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
567
ent/follow_update.go
Normal file
567
ent/follow_update.go
Normal file
|
|
@ -0,0 +1,567 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/follow"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
// FollowUpdate is the builder for updating Follow entities.
|
||||
type FollowUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *FollowMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the FollowUpdate builder.
|
||||
func (fu *FollowUpdate) Where(ps ...predicate.Follow) *FollowUpdate {
|
||||
fu.mutation.Where(ps...)
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetIsRemote sets the "isRemote" field.
|
||||
func (fu *FollowUpdate) SetIsRemote(b bool) *FollowUpdate {
|
||||
fu.mutation.SetIsRemote(b)
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetNillableIsRemote sets the "isRemote" field if the given value is not nil.
|
||||
func (fu *FollowUpdate) SetNillableIsRemote(b *bool) *FollowUpdate {
|
||||
if b != nil {
|
||||
fu.SetIsRemote(*b)
|
||||
}
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetURI sets the "uri" field.
|
||||
func (fu *FollowUpdate) SetURI(s string) *FollowUpdate {
|
||||
fu.mutation.SetURI(s)
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetNillableURI sets the "uri" field if the given value is not nil.
|
||||
func (fu *FollowUpdate) SetNillableURI(s *string) *FollowUpdate {
|
||||
if s != nil {
|
||||
fu.SetURI(*s)
|
||||
}
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (fu *FollowUpdate) SetExtensions(l lysand.Extensions) *FollowUpdate {
|
||||
fu.mutation.SetExtensions(l)
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (fu *FollowUpdate) SetUpdatedAt(t time.Time) *FollowUpdate {
|
||||
fu.mutation.SetUpdatedAt(t)
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (fu *FollowUpdate) SetStatus(f follow.Status) *FollowUpdate {
|
||||
fu.mutation.SetStatus(f)
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (fu *FollowUpdate) SetNillableStatus(f *follow.Status) *FollowUpdate {
|
||||
if f != nil {
|
||||
fu.SetStatus(*f)
|
||||
}
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetFollowerID sets the "follower" edge to the User entity by ID.
|
||||
func (fu *FollowUpdate) SetFollowerID(id uuid.UUID) *FollowUpdate {
|
||||
fu.mutation.SetFollowerID(id)
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetFollower sets the "follower" edge to the User entity.
|
||||
func (fu *FollowUpdate) SetFollower(u *User) *FollowUpdate {
|
||||
return fu.SetFollowerID(u.ID)
|
||||
}
|
||||
|
||||
// SetFolloweeID sets the "followee" edge to the User entity by ID.
|
||||
func (fu *FollowUpdate) SetFolloweeID(id uuid.UUID) *FollowUpdate {
|
||||
fu.mutation.SetFolloweeID(id)
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetFollowee sets the "followee" edge to the User entity.
|
||||
func (fu *FollowUpdate) SetFollowee(u *User) *FollowUpdate {
|
||||
return fu.SetFolloweeID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the FollowMutation object of the builder.
|
||||
func (fu *FollowUpdate) Mutation() *FollowMutation {
|
||||
return fu.mutation
|
||||
}
|
||||
|
||||
// ClearFollower clears the "follower" edge to the User entity.
|
||||
func (fu *FollowUpdate) ClearFollower() *FollowUpdate {
|
||||
fu.mutation.ClearFollower()
|
||||
return fu
|
||||
}
|
||||
|
||||
// ClearFollowee clears the "followee" edge to the User entity.
|
||||
func (fu *FollowUpdate) ClearFollowee() *FollowUpdate {
|
||||
fu.mutation.ClearFollowee()
|
||||
return fu
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (fu *FollowUpdate) Save(ctx context.Context) (int, error) {
|
||||
fu.defaults()
|
||||
return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (fu *FollowUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := fu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (fu *FollowUpdate) Exec(ctx context.Context) error {
|
||||
_, err := fu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (fu *FollowUpdate) ExecX(ctx context.Context) {
|
||||
if err := fu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (fu *FollowUpdate) defaults() {
|
||||
if _, ok := fu.mutation.UpdatedAt(); !ok {
|
||||
v := follow.UpdateDefaultUpdatedAt()
|
||||
fu.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (fu *FollowUpdate) check() error {
|
||||
if v, ok := fu.mutation.URI(); ok {
|
||||
if err := follow.URIValidator(v); err != nil {
|
||||
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "Follow.uri": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := fu.mutation.Status(); ok {
|
||||
if err := follow.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Follow.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := fu.mutation.FollowerID(); fu.mutation.FollowerCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Follow.follower"`)
|
||||
}
|
||||
if _, ok := fu.mutation.FolloweeID(); fu.mutation.FolloweeCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Follow.followee"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fu *FollowUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := fu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(follow.Table, follow.Columns, sqlgraph.NewFieldSpec(follow.FieldID, field.TypeUUID))
|
||||
if ps := fu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := fu.mutation.IsRemote(); ok {
|
||||
_spec.SetField(follow.FieldIsRemote, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := fu.mutation.URI(); ok {
|
||||
_spec.SetField(follow.FieldURI, field.TypeString, value)
|
||||
}
|
||||
if value, ok := fu.mutation.Extensions(); ok {
|
||||
_spec.SetField(follow.FieldExtensions, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := fu.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(follow.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := fu.mutation.Status(); ok {
|
||||
_spec.SetField(follow.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
if fu.mutation.FollowerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: follow.FollowerTable,
|
||||
Columns: []string{follow.FollowerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := fu.mutation.FollowerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: follow.FollowerTable,
|
||||
Columns: []string{follow.FollowerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if fu.mutation.FolloweeCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: follow.FolloweeTable,
|
||||
Columns: []string{follow.FolloweeColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := fu.mutation.FolloweeIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: follow.FolloweeTable,
|
||||
Columns: []string{follow.FolloweeColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, fu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{follow.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
fu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// FollowUpdateOne is the builder for updating a single Follow entity.
|
||||
type FollowUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *FollowMutation
|
||||
}
|
||||
|
||||
// SetIsRemote sets the "isRemote" field.
|
||||
func (fuo *FollowUpdateOne) SetIsRemote(b bool) *FollowUpdateOne {
|
||||
fuo.mutation.SetIsRemote(b)
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetNillableIsRemote sets the "isRemote" field if the given value is not nil.
|
||||
func (fuo *FollowUpdateOne) SetNillableIsRemote(b *bool) *FollowUpdateOne {
|
||||
if b != nil {
|
||||
fuo.SetIsRemote(*b)
|
||||
}
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetURI sets the "uri" field.
|
||||
func (fuo *FollowUpdateOne) SetURI(s string) *FollowUpdateOne {
|
||||
fuo.mutation.SetURI(s)
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetNillableURI sets the "uri" field if the given value is not nil.
|
||||
func (fuo *FollowUpdateOne) SetNillableURI(s *string) *FollowUpdateOne {
|
||||
if s != nil {
|
||||
fuo.SetURI(*s)
|
||||
}
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (fuo *FollowUpdateOne) SetExtensions(l lysand.Extensions) *FollowUpdateOne {
|
||||
fuo.mutation.SetExtensions(l)
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (fuo *FollowUpdateOne) SetUpdatedAt(t time.Time) *FollowUpdateOne {
|
||||
fuo.mutation.SetUpdatedAt(t)
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (fuo *FollowUpdateOne) SetStatus(f follow.Status) *FollowUpdateOne {
|
||||
fuo.mutation.SetStatus(f)
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (fuo *FollowUpdateOne) SetNillableStatus(f *follow.Status) *FollowUpdateOne {
|
||||
if f != nil {
|
||||
fuo.SetStatus(*f)
|
||||
}
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetFollowerID sets the "follower" edge to the User entity by ID.
|
||||
func (fuo *FollowUpdateOne) SetFollowerID(id uuid.UUID) *FollowUpdateOne {
|
||||
fuo.mutation.SetFollowerID(id)
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetFollower sets the "follower" edge to the User entity.
|
||||
func (fuo *FollowUpdateOne) SetFollower(u *User) *FollowUpdateOne {
|
||||
return fuo.SetFollowerID(u.ID)
|
||||
}
|
||||
|
||||
// SetFolloweeID sets the "followee" edge to the User entity by ID.
|
||||
func (fuo *FollowUpdateOne) SetFolloweeID(id uuid.UUID) *FollowUpdateOne {
|
||||
fuo.mutation.SetFolloweeID(id)
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetFollowee sets the "followee" edge to the User entity.
|
||||
func (fuo *FollowUpdateOne) SetFollowee(u *User) *FollowUpdateOne {
|
||||
return fuo.SetFolloweeID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the FollowMutation object of the builder.
|
||||
func (fuo *FollowUpdateOne) Mutation() *FollowMutation {
|
||||
return fuo.mutation
|
||||
}
|
||||
|
||||
// ClearFollower clears the "follower" edge to the User entity.
|
||||
func (fuo *FollowUpdateOne) ClearFollower() *FollowUpdateOne {
|
||||
fuo.mutation.ClearFollower()
|
||||
return fuo
|
||||
}
|
||||
|
||||
// ClearFollowee clears the "followee" edge to the User entity.
|
||||
func (fuo *FollowUpdateOne) ClearFollowee() *FollowUpdateOne {
|
||||
fuo.mutation.ClearFollowee()
|
||||
return fuo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the FollowUpdate builder.
|
||||
func (fuo *FollowUpdateOne) Where(ps ...predicate.Follow) *FollowUpdateOne {
|
||||
fuo.mutation.Where(ps...)
|
||||
return fuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (fuo *FollowUpdateOne) Select(field string, fields ...string) *FollowUpdateOne {
|
||||
fuo.fields = append([]string{field}, fields...)
|
||||
return fuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Follow entity.
|
||||
func (fuo *FollowUpdateOne) Save(ctx context.Context) (*Follow, error) {
|
||||
fuo.defaults()
|
||||
return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (fuo *FollowUpdateOne) SaveX(ctx context.Context) *Follow {
|
||||
node, err := fuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (fuo *FollowUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := fuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (fuo *FollowUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := fuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (fuo *FollowUpdateOne) defaults() {
|
||||
if _, ok := fuo.mutation.UpdatedAt(); !ok {
|
||||
v := follow.UpdateDefaultUpdatedAt()
|
||||
fuo.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (fuo *FollowUpdateOne) check() error {
|
||||
if v, ok := fuo.mutation.URI(); ok {
|
||||
if err := follow.URIValidator(v); err != nil {
|
||||
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "Follow.uri": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := fuo.mutation.Status(); ok {
|
||||
if err := follow.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Follow.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := fuo.mutation.FollowerID(); fuo.mutation.FollowerCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Follow.follower"`)
|
||||
}
|
||||
if _, ok := fuo.mutation.FolloweeID(); fuo.mutation.FolloweeCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Follow.followee"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fuo *FollowUpdateOne) sqlSave(ctx context.Context) (_node *Follow, err error) {
|
||||
if err := fuo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(follow.Table, follow.Columns, sqlgraph.NewFieldSpec(follow.FieldID, field.TypeUUID))
|
||||
id, ok := fuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Follow.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := fuo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, follow.FieldID)
|
||||
for _, f := range fields {
|
||||
if !follow.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != follow.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := fuo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := fuo.mutation.IsRemote(); ok {
|
||||
_spec.SetField(follow.FieldIsRemote, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := fuo.mutation.URI(); ok {
|
||||
_spec.SetField(follow.FieldURI, field.TypeString, value)
|
||||
}
|
||||
if value, ok := fuo.mutation.Extensions(); ok {
|
||||
_spec.SetField(follow.FieldExtensions, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := fuo.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(follow.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := fuo.mutation.Status(); ok {
|
||||
_spec.SetField(follow.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
if fuo.mutation.FollowerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: follow.FollowerTable,
|
||||
Columns: []string{follow.FollowerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := fuo.mutation.FollowerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: follow.FollowerTable,
|
||||
Columns: []string{follow.FollowerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if fuo.mutation.FolloweeCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: follow.FolloweeTable,
|
||||
Columns: []string{follow.FolloweeColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := fuo.mutation.FolloweeIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: follow.FolloweeTable,
|
||||
Columns: []string{follow.FolloweeColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Follow{config: fuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, fuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{follow.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
fuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
3
ent/generate.go
Normal file
3
ent/generate.go
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
package ent
|
||||
|
||||
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --feature schema/snapshot --feature sql/upsert ./schema
|
||||
259
ent/hook/hook.go
Normal file
259
ent/hook/hook.go
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package hook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
)
|
||||
|
||||
// The AttachmentFunc type is an adapter to allow the use of ordinary
|
||||
// function as Attachment mutator.
|
||||
type AttachmentFunc func(context.Context, *ent.AttachmentMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f AttachmentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.AttachmentMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AttachmentMutation", m)
|
||||
}
|
||||
|
||||
// The FollowFunc type is an adapter to allow the use of ordinary
|
||||
// function as Follow mutator.
|
||||
type FollowFunc func(context.Context, *ent.FollowMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f FollowFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.FollowMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.FollowMutation", m)
|
||||
}
|
||||
|
||||
// The ImageFunc type is an adapter to allow the use of ordinary
|
||||
// function as Image mutator.
|
||||
type ImageFunc func(context.Context, *ent.ImageMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f ImageFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.ImageMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ImageMutation", m)
|
||||
}
|
||||
|
||||
// The NoteFunc type is an adapter to allow the use of ordinary
|
||||
// function as Note mutator.
|
||||
type NoteFunc func(context.Context, *ent.NoteMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f NoteFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.NoteMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.NoteMutation", m)
|
||||
}
|
||||
|
||||
// The ServerMetadataFunc type is an adapter to allow the use of ordinary
|
||||
// function as ServerMetadata mutator.
|
||||
type ServerMetadataFunc func(context.Context, *ent.ServerMetadataMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f ServerMetadataFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.ServerMetadataMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ServerMetadataMutation", m)
|
||||
}
|
||||
|
||||
// The UserFunc type is an adapter to allow the use of ordinary
|
||||
// function as User mutator.
|
||||
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.UserMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m)
|
||||
}
|
||||
|
||||
// Condition is a hook condition function.
|
||||
type Condition func(context.Context, ent.Mutation) bool
|
||||
|
||||
// And groups conditions with the AND operator.
|
||||
func And(first, second Condition, rest ...Condition) Condition {
|
||||
return func(ctx context.Context, m ent.Mutation) bool {
|
||||
if !first(ctx, m) || !second(ctx, m) {
|
||||
return false
|
||||
}
|
||||
for _, cond := range rest {
|
||||
if !cond(ctx, m) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Or groups conditions with the OR operator.
|
||||
func Or(first, second Condition, rest ...Condition) Condition {
|
||||
return func(ctx context.Context, m ent.Mutation) bool {
|
||||
if first(ctx, m) || second(ctx, m) {
|
||||
return true
|
||||
}
|
||||
for _, cond := range rest {
|
||||
if cond(ctx, m) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Not negates a given condition.
|
||||
func Not(cond Condition) Condition {
|
||||
return func(ctx context.Context, m ent.Mutation) bool {
|
||||
return !cond(ctx, m)
|
||||
}
|
||||
}
|
||||
|
||||
// HasOp is a condition testing mutation operation.
|
||||
func HasOp(op ent.Op) Condition {
|
||||
return func(_ context.Context, m ent.Mutation) bool {
|
||||
return m.Op().Is(op)
|
||||
}
|
||||
}
|
||||
|
||||
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||
func HasAddedFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m ent.Mutation) bool {
|
||||
if _, exists := m.AddedField(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if _, exists := m.AddedField(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||
func HasClearedFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m ent.Mutation) bool {
|
||||
if exists := m.FieldCleared(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if exists := m.FieldCleared(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// HasFields is a condition validating `.Field` on fields.
|
||||
func HasFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m ent.Mutation) bool {
|
||||
if _, exists := m.Field(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if _, exists := m.Field(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// If executes the given hook under condition.
|
||||
//
|
||||
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||
func If(hk ent.Hook, cond Condition) ent.Hook {
|
||||
return func(next ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if cond(ctx, m) {
|
||||
return hk(next).Mutate(ctx, m)
|
||||
}
|
||||
return next.Mutate(ctx, m)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// On executes the given hook only for the given operation.
|
||||
//
|
||||
// hook.On(Log, ent.Delete|ent.Create)
|
||||
func On(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, HasOp(op))
|
||||
}
|
||||
|
||||
// Unless skips the given hook only for the given operation.
|
||||
//
|
||||
// hook.Unless(Log, ent.Update|ent.UpdateOne)
|
||||
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
// return []ent.Hook{
|
||||
// Reject(ent.Delete|ent.Update),
|
||||
// }
|
||||
// }
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
// Chain acts as a list of hooks and is effectively immutable.
|
||||
// Once created, it will always hold the same set of hooks in the same order.
|
||||
type Chain struct {
|
||||
hooks []ent.Hook
|
||||
}
|
||||
|
||||
// NewChain creates a new chain of hooks.
|
||||
func NewChain(hooks ...ent.Hook) Chain {
|
||||
return Chain{append([]ent.Hook(nil), hooks...)}
|
||||
}
|
||||
|
||||
// Hook chains the list of hooks and returns the final hook.
|
||||
func (c Chain) Hook() ent.Hook {
|
||||
return func(mutator ent.Mutator) ent.Mutator {
|
||||
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||
mutator = c.hooks[i](mutator)
|
||||
}
|
||||
return mutator
|
||||
}
|
||||
}
|
||||
|
||||
// Append extends a chain, adding the specified hook
|
||||
// as the last ones in the mutation flow.
|
||||
func (c Chain) Append(hooks ...ent.Hook) Chain {
|
||||
newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks))
|
||||
newHooks = append(newHooks, c.hooks...)
|
||||
newHooks = append(newHooks, hooks...)
|
||||
return Chain{newHooks}
|
||||
}
|
||||
|
||||
// Extend extends a chain, adding the specified chain
|
||||
// as the last ones in the mutation flow.
|
||||
func (c Chain) Extend(chain Chain) Chain {
|
||||
return c.Append(chain.hooks...)
|
||||
}
|
||||
114
ent/image.go
Normal file
114
ent/image.go
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/lysand-org/versia-go/ent/image"
|
||||
)
|
||||
|
||||
// Image is the model entity for the Image schema.
|
||||
type Image struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// URL holds the value of the "url" field.
|
||||
URL string `json:"url,omitempty"`
|
||||
// MimeType holds the value of the "mimeType" field.
|
||||
MimeType string `json:"mimeType,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Image) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case image.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case image.FieldURL, image.FieldMimeType:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Image fields.
|
||||
func (i *Image) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for j := range columns {
|
||||
switch columns[j] {
|
||||
case image.FieldID:
|
||||
value, ok := values[j].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
i.ID = int(value.Int64)
|
||||
case image.FieldURL:
|
||||
if value, ok := values[j].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field url", values[j])
|
||||
} else if value.Valid {
|
||||
i.URL = value.String
|
||||
}
|
||||
case image.FieldMimeType:
|
||||
if value, ok := values[j].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field mimeType", values[j])
|
||||
} else if value.Valid {
|
||||
i.MimeType = value.String
|
||||
}
|
||||
default:
|
||||
i.selectValues.Set(columns[j], values[j])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Image.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (i *Image) Value(name string) (ent.Value, error) {
|
||||
return i.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Image.
|
||||
// Note that you need to call Image.Unwrap() before calling this method if this Image
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (i *Image) Update() *ImageUpdateOne {
|
||||
return NewImageClient(i.config).UpdateOne(i)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Image entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (i *Image) Unwrap() *Image {
|
||||
_tx, ok := i.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Image is not a transactional entity")
|
||||
}
|
||||
i.config.driver = _tx.drv
|
||||
return i
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (i *Image) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Image(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", i.ID))
|
||||
builder.WriteString("url=")
|
||||
builder.WriteString(i.URL)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("mimeType=")
|
||||
builder.WriteString(i.MimeType)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Images is a parsable slice of Image.
|
||||
type Images []*Image
|
||||
55
ent/image/image.go
Normal file
55
ent/image/image.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package image
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the image type in the database.
|
||||
Label = "image"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldURL holds the string denoting the url field in the database.
|
||||
FieldURL = "url"
|
||||
// FieldMimeType holds the string denoting the mimetype field in the database.
|
||||
FieldMimeType = "mime_type"
|
||||
// Table holds the table name of the image in the database.
|
||||
Table = "images"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for image fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldURL,
|
||||
FieldMimeType,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the Image queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByURL orders the results by the url field.
|
||||
func ByURL(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldURL, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByMimeType orders the results by the mimeType field.
|
||||
func ByMimeType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldMimeType, opts...).ToFunc()
|
||||
}
|
||||
208
ent/image/where.go
Normal file
208
ent/image/where.go
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package image
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Image {
|
||||
return predicate.Image(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Image {
|
||||
return predicate.Image(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Image {
|
||||
return predicate.Image(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Image {
|
||||
return predicate.Image(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Image {
|
||||
return predicate.Image(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Image {
|
||||
return predicate.Image(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Image {
|
||||
return predicate.Image(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Image {
|
||||
return predicate.Image(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Image {
|
||||
return predicate.Image(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// URL applies equality check predicate on the "url" field. It's identical to URLEQ.
|
||||
func URL(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldEQ(FieldURL, v))
|
||||
}
|
||||
|
||||
// MimeType applies equality check predicate on the "mimeType" field. It's identical to MimeTypeEQ.
|
||||
func MimeType(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldEQ(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// URLEQ applies the EQ predicate on the "url" field.
|
||||
func URLEQ(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldEQ(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLNEQ applies the NEQ predicate on the "url" field.
|
||||
func URLNEQ(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldNEQ(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLIn applies the In predicate on the "url" field.
|
||||
func URLIn(vs ...string) predicate.Image {
|
||||
return predicate.Image(sql.FieldIn(FieldURL, vs...))
|
||||
}
|
||||
|
||||
// URLNotIn applies the NotIn predicate on the "url" field.
|
||||
func URLNotIn(vs ...string) predicate.Image {
|
||||
return predicate.Image(sql.FieldNotIn(FieldURL, vs...))
|
||||
}
|
||||
|
||||
// URLGT applies the GT predicate on the "url" field.
|
||||
func URLGT(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldGT(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLGTE applies the GTE predicate on the "url" field.
|
||||
func URLGTE(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldGTE(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLLT applies the LT predicate on the "url" field.
|
||||
func URLLT(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldLT(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLLTE applies the LTE predicate on the "url" field.
|
||||
func URLLTE(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldLTE(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLContains applies the Contains predicate on the "url" field.
|
||||
func URLContains(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldContains(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLHasPrefix applies the HasPrefix predicate on the "url" field.
|
||||
func URLHasPrefix(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldHasPrefix(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLHasSuffix applies the HasSuffix predicate on the "url" field.
|
||||
func URLHasSuffix(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldHasSuffix(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLEqualFold applies the EqualFold predicate on the "url" field.
|
||||
func URLEqualFold(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldEqualFold(FieldURL, v))
|
||||
}
|
||||
|
||||
// URLContainsFold applies the ContainsFold predicate on the "url" field.
|
||||
func URLContainsFold(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldContainsFold(FieldURL, v))
|
||||
}
|
||||
|
||||
// MimeTypeEQ applies the EQ predicate on the "mimeType" field.
|
||||
func MimeTypeEQ(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldEQ(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeNEQ applies the NEQ predicate on the "mimeType" field.
|
||||
func MimeTypeNEQ(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldNEQ(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeIn applies the In predicate on the "mimeType" field.
|
||||
func MimeTypeIn(vs ...string) predicate.Image {
|
||||
return predicate.Image(sql.FieldIn(FieldMimeType, vs...))
|
||||
}
|
||||
|
||||
// MimeTypeNotIn applies the NotIn predicate on the "mimeType" field.
|
||||
func MimeTypeNotIn(vs ...string) predicate.Image {
|
||||
return predicate.Image(sql.FieldNotIn(FieldMimeType, vs...))
|
||||
}
|
||||
|
||||
// MimeTypeGT applies the GT predicate on the "mimeType" field.
|
||||
func MimeTypeGT(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldGT(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeGTE applies the GTE predicate on the "mimeType" field.
|
||||
func MimeTypeGTE(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldGTE(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeLT applies the LT predicate on the "mimeType" field.
|
||||
func MimeTypeLT(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldLT(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeLTE applies the LTE predicate on the "mimeType" field.
|
||||
func MimeTypeLTE(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldLTE(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeContains applies the Contains predicate on the "mimeType" field.
|
||||
func MimeTypeContains(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldContains(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeHasPrefix applies the HasPrefix predicate on the "mimeType" field.
|
||||
func MimeTypeHasPrefix(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldHasPrefix(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeHasSuffix applies the HasSuffix predicate on the "mimeType" field.
|
||||
func MimeTypeHasSuffix(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldHasSuffix(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeEqualFold applies the EqualFold predicate on the "mimeType" field.
|
||||
func MimeTypeEqualFold(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldEqualFold(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// MimeTypeContainsFold applies the ContainsFold predicate on the "mimeType" field.
|
||||
func MimeTypeContainsFold(v string) predicate.Image {
|
||||
return predicate.Image(sql.FieldContainsFold(FieldMimeType, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Image) predicate.Image {
|
||||
return predicate.Image(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Image) predicate.Image {
|
||||
return predicate.Image(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Image) predicate.Image {
|
||||
return predicate.Image(sql.NotPredicates(p))
|
||||
}
|
||||
507
ent/image_create.go
Normal file
507
ent/image_create.go
Normal file
|
|
@ -0,0 +1,507 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/lysand-org/versia-go/ent/image"
|
||||
)
|
||||
|
||||
// ImageCreate is the builder for creating a Image entity.
|
||||
type ImageCreate struct {
|
||||
config
|
||||
mutation *ImageMutation
|
||||
hooks []Hook
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// SetURL sets the "url" field.
|
||||
func (ic *ImageCreate) SetURL(s string) *ImageCreate {
|
||||
ic.mutation.SetURL(s)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetMimeType sets the "mimeType" field.
|
||||
func (ic *ImageCreate) SetMimeType(s string) *ImageCreate {
|
||||
ic.mutation.SetMimeType(s)
|
||||
return ic
|
||||
}
|
||||
|
||||
// Mutation returns the ImageMutation object of the builder.
|
||||
func (ic *ImageCreate) Mutation() *ImageMutation {
|
||||
return ic.mutation
|
||||
}
|
||||
|
||||
// Save creates the Image in the database.
|
||||
func (ic *ImageCreate) Save(ctx context.Context) (*Image, error) {
|
||||
return withHooks(ctx, ic.sqlSave, ic.mutation, ic.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (ic *ImageCreate) SaveX(ctx context.Context) *Image {
|
||||
v, err := ic.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (ic *ImageCreate) Exec(ctx context.Context) error {
|
||||
_, err := ic.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ic *ImageCreate) ExecX(ctx context.Context) {
|
||||
if err := ic.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (ic *ImageCreate) check() error {
|
||||
if _, ok := ic.mutation.URL(); !ok {
|
||||
return &ValidationError{Name: "url", err: errors.New(`ent: missing required field "Image.url"`)}
|
||||
}
|
||||
if _, ok := ic.mutation.MimeType(); !ok {
|
||||
return &ValidationError{Name: "mimeType", err: errors.New(`ent: missing required field "Image.mimeType"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ic *ImageCreate) sqlSave(ctx context.Context) (*Image, error) {
|
||||
if err := ic.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := ic.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, ic.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
ic.mutation.id = &_node.ID
|
||||
ic.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (ic *ImageCreate) createSpec() (*Image, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Image{config: ic.config}
|
||||
_spec = sqlgraph.NewCreateSpec(image.Table, sqlgraph.NewFieldSpec(image.FieldID, field.TypeInt))
|
||||
)
|
||||
_spec.OnConflict = ic.conflict
|
||||
if value, ok := ic.mutation.URL(); ok {
|
||||
_spec.SetField(image.FieldURL, field.TypeString, value)
|
||||
_node.URL = value
|
||||
}
|
||||
if value, ok := ic.mutation.MimeType(); ok {
|
||||
_spec.SetField(image.FieldMimeType, field.TypeString, value)
|
||||
_node.MimeType = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.Image.Create().
|
||||
// SetURL(v).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.ImageUpsert) {
|
||||
// SetURL(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (ic *ImageCreate) OnConflict(opts ...sql.ConflictOption) *ImageUpsertOne {
|
||||
ic.conflict = opts
|
||||
return &ImageUpsertOne{
|
||||
create: ic,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.Image.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (ic *ImageCreate) OnConflictColumns(columns ...string) *ImageUpsertOne {
|
||||
ic.conflict = append(ic.conflict, sql.ConflictColumns(columns...))
|
||||
return &ImageUpsertOne{
|
||||
create: ic,
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
// ImageUpsertOne is the builder for "upsert"-ing
|
||||
// one Image node.
|
||||
ImageUpsertOne struct {
|
||||
create *ImageCreate
|
||||
}
|
||||
|
||||
// ImageUpsert is the "OnConflict" setter.
|
||||
ImageUpsert struct {
|
||||
*sql.UpdateSet
|
||||
}
|
||||
)
|
||||
|
||||
// SetURL sets the "url" field.
|
||||
func (u *ImageUpsert) SetURL(v string) *ImageUpsert {
|
||||
u.Set(image.FieldURL, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateURL sets the "url" field to the value that was provided on create.
|
||||
func (u *ImageUpsert) UpdateURL() *ImageUpsert {
|
||||
u.SetExcluded(image.FieldURL)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetMimeType sets the "mimeType" field.
|
||||
func (u *ImageUpsert) SetMimeType(v string) *ImageUpsert {
|
||||
u.Set(image.FieldMimeType, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateMimeType sets the "mimeType" field to the value that was provided on create.
|
||||
func (u *ImageUpsert) UpdateMimeType() *ImageUpsert {
|
||||
u.SetExcluded(image.FieldMimeType)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.Image.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *ImageUpsertOne) UpdateNewValues() *ImageUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.Image.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *ImageUpsertOne) Ignore() *ImageUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *ImageUpsertOne) DoNothing() *ImageUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the ImageCreate.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *ImageUpsertOne) Update(set func(*ImageUpsert)) *ImageUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&ImageUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetURL sets the "url" field.
|
||||
func (u *ImageUpsertOne) SetURL(v string) *ImageUpsertOne {
|
||||
return u.Update(func(s *ImageUpsert) {
|
||||
s.SetURL(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateURL sets the "url" field to the value that was provided on create.
|
||||
func (u *ImageUpsertOne) UpdateURL() *ImageUpsertOne {
|
||||
return u.Update(func(s *ImageUpsert) {
|
||||
s.UpdateURL()
|
||||
})
|
||||
}
|
||||
|
||||
// SetMimeType sets the "mimeType" field.
|
||||
func (u *ImageUpsertOne) SetMimeType(v string) *ImageUpsertOne {
|
||||
return u.Update(func(s *ImageUpsert) {
|
||||
s.SetMimeType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateMimeType sets the "mimeType" field to the value that was provided on create.
|
||||
func (u *ImageUpsertOne) UpdateMimeType() *ImageUpsertOne {
|
||||
return u.Update(func(s *ImageUpsert) {
|
||||
s.UpdateMimeType()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *ImageUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for ImageCreate.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *ImageUpsertOne) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
||||
func (u *ImageUpsertOne) ID(ctx context.Context) (id int, err error) {
|
||||
node, err := u.create.Save(ctx)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
return node.ID, nil
|
||||
}
|
||||
|
||||
// IDX is like ID, but panics if an error occurs.
|
||||
func (u *ImageUpsertOne) IDX(ctx context.Context) int {
|
||||
id, err := u.ID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// ImageCreateBulk is the builder for creating many Image entities in bulk.
|
||||
type ImageCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*ImageCreate
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// Save creates the Image entities in the database.
|
||||
func (icb *ImageCreateBulk) Save(ctx context.Context) ([]*Image, error) {
|
||||
if icb.err != nil {
|
||||
return nil, icb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(icb.builders))
|
||||
nodes := make([]*Image, len(icb.builders))
|
||||
mutators := make([]Mutator, len(icb.builders))
|
||||
for i := range icb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := icb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*ImageMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, icb.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
spec.OnConflict = icb.conflict
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, icb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, icb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (icb *ImageCreateBulk) SaveX(ctx context.Context) []*Image {
|
||||
v, err := icb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (icb *ImageCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := icb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (icb *ImageCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := icb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.Image.CreateBulk(builders...).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.ImageUpsert) {
|
||||
// SetURL(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (icb *ImageCreateBulk) OnConflict(opts ...sql.ConflictOption) *ImageUpsertBulk {
|
||||
icb.conflict = opts
|
||||
return &ImageUpsertBulk{
|
||||
create: icb,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.Image.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (icb *ImageCreateBulk) OnConflictColumns(columns ...string) *ImageUpsertBulk {
|
||||
icb.conflict = append(icb.conflict, sql.ConflictColumns(columns...))
|
||||
return &ImageUpsertBulk{
|
||||
create: icb,
|
||||
}
|
||||
}
|
||||
|
||||
// ImageUpsertBulk is the builder for "upsert"-ing
|
||||
// a bulk of Image nodes.
|
||||
type ImageUpsertBulk struct {
|
||||
create *ImageCreateBulk
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that
|
||||
// were set on create. Using this option is equivalent to using:
|
||||
//
|
||||
// client.Image.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *ImageUpsertBulk) UpdateNewValues() *ImageUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.Image.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *ImageUpsertBulk) Ignore() *ImageUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *ImageUpsertBulk) DoNothing() *ImageUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the ImageCreateBulk.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *ImageUpsertBulk) Update(set func(*ImageUpsert)) *ImageUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&ImageUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetURL sets the "url" field.
|
||||
func (u *ImageUpsertBulk) SetURL(v string) *ImageUpsertBulk {
|
||||
return u.Update(func(s *ImageUpsert) {
|
||||
s.SetURL(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateURL sets the "url" field to the value that was provided on create.
|
||||
func (u *ImageUpsertBulk) UpdateURL() *ImageUpsertBulk {
|
||||
return u.Update(func(s *ImageUpsert) {
|
||||
s.UpdateURL()
|
||||
})
|
||||
}
|
||||
|
||||
// SetMimeType sets the "mimeType" field.
|
||||
func (u *ImageUpsertBulk) SetMimeType(v string) *ImageUpsertBulk {
|
||||
return u.Update(func(s *ImageUpsert) {
|
||||
s.SetMimeType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateMimeType sets the "mimeType" field to the value that was provided on create.
|
||||
func (u *ImageUpsertBulk) UpdateMimeType() *ImageUpsertBulk {
|
||||
return u.Update(func(s *ImageUpsert) {
|
||||
s.UpdateMimeType()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *ImageUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
return u.create.err
|
||||
}
|
||||
for i, b := range u.create.builders {
|
||||
if len(b.conflict) != 0 {
|
||||
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the ImageCreateBulk instead", i)
|
||||
}
|
||||
}
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for ImageCreateBulk.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *ImageUpsertBulk) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
88
ent/image_delete.go
Normal file
88
ent/image_delete.go
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/lysand-org/versia-go/ent/image"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
)
|
||||
|
||||
// ImageDelete is the builder for deleting a Image entity.
|
||||
type ImageDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ImageMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ImageDelete builder.
|
||||
func (id *ImageDelete) Where(ps ...predicate.Image) *ImageDelete {
|
||||
id.mutation.Where(ps...)
|
||||
return id
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (id *ImageDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, id.sqlExec, id.mutation, id.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (id *ImageDelete) ExecX(ctx context.Context) int {
|
||||
n, err := id.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (id *ImageDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(image.Table, sqlgraph.NewFieldSpec(image.FieldID, field.TypeInt))
|
||||
if ps := id.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, id.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
id.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// ImageDeleteOne is the builder for deleting a single Image entity.
|
||||
type ImageDeleteOne struct {
|
||||
id *ImageDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ImageDelete builder.
|
||||
func (ido *ImageDeleteOne) Where(ps ...predicate.Image) *ImageDeleteOne {
|
||||
ido.id.mutation.Where(ps...)
|
||||
return ido
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (ido *ImageDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := ido.id.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{image.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ido *ImageDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := ido.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
526
ent/image_query.go
Normal file
526
ent/image_query.go
Normal file
|
|
@ -0,0 +1,526 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/lysand-org/versia-go/ent/image"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
)
|
||||
|
||||
// ImageQuery is the builder for querying Image entities.
|
||||
type ImageQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []image.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Image
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the ImageQuery builder.
|
||||
func (iq *ImageQuery) Where(ps ...predicate.Image) *ImageQuery {
|
||||
iq.predicates = append(iq.predicates, ps...)
|
||||
return iq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (iq *ImageQuery) Limit(limit int) *ImageQuery {
|
||||
iq.ctx.Limit = &limit
|
||||
return iq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (iq *ImageQuery) Offset(offset int) *ImageQuery {
|
||||
iq.ctx.Offset = &offset
|
||||
return iq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (iq *ImageQuery) Unique(unique bool) *ImageQuery {
|
||||
iq.ctx.Unique = &unique
|
||||
return iq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (iq *ImageQuery) Order(o ...image.OrderOption) *ImageQuery {
|
||||
iq.order = append(iq.order, o...)
|
||||
return iq
|
||||
}
|
||||
|
||||
// First returns the first Image entity from the query.
|
||||
// Returns a *NotFoundError when no Image was found.
|
||||
func (iq *ImageQuery) First(ctx context.Context) (*Image, error) {
|
||||
nodes, err := iq.Limit(1).All(setContextOp(ctx, iq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{image.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (iq *ImageQuery) FirstX(ctx context.Context) *Image {
|
||||
node, err := iq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Image ID from the query.
|
||||
// Returns a *NotFoundError when no Image ID was found.
|
||||
func (iq *ImageQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = iq.Limit(1).IDs(setContextOp(ctx, iq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{image.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (iq *ImageQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := iq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Image entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Image entity is found.
|
||||
// Returns a *NotFoundError when no Image entities are found.
|
||||
func (iq *ImageQuery) Only(ctx context.Context) (*Image, error) {
|
||||
nodes, err := iq.Limit(2).All(setContextOp(ctx, iq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{image.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{image.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (iq *ImageQuery) OnlyX(ctx context.Context) *Image {
|
||||
node, err := iq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Image ID in the query.
|
||||
// Returns a *NotSingularError when more than one Image ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (iq *ImageQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = iq.Limit(2).IDs(setContextOp(ctx, iq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{image.Label}
|
||||
default:
|
||||
err = &NotSingularError{image.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (iq *ImageQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := iq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Images.
|
||||
func (iq *ImageQuery) All(ctx context.Context) ([]*Image, error) {
|
||||
ctx = setContextOp(ctx, iq.ctx, "All")
|
||||
if err := iq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Image, *ImageQuery]()
|
||||
return withInterceptors[[]*Image](ctx, iq, qr, iq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (iq *ImageQuery) AllX(ctx context.Context) []*Image {
|
||||
nodes, err := iq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Image IDs.
|
||||
func (iq *ImageQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if iq.ctx.Unique == nil && iq.path != nil {
|
||||
iq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, iq.ctx, "IDs")
|
||||
if err = iq.Select(image.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (iq *ImageQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := iq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (iq *ImageQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, iq.ctx, "Count")
|
||||
if err := iq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, iq, querierCount[*ImageQuery](), iq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (iq *ImageQuery) CountX(ctx context.Context) int {
|
||||
count, err := iq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (iq *ImageQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, iq.ctx, "Exist")
|
||||
switch _, err := iq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (iq *ImageQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := iq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the ImageQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (iq *ImageQuery) Clone() *ImageQuery {
|
||||
if iq == nil {
|
||||
return nil
|
||||
}
|
||||
return &ImageQuery{
|
||||
config: iq.config,
|
||||
ctx: iq.ctx.Clone(),
|
||||
order: append([]image.OrderOption{}, iq.order...),
|
||||
inters: append([]Interceptor{}, iq.inters...),
|
||||
predicates: append([]predicate.Image{}, iq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: iq.sql.Clone(),
|
||||
path: iq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// URL string `json:"url,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Image.Query().
|
||||
// GroupBy(image.FieldURL).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (iq *ImageQuery) GroupBy(field string, fields ...string) *ImageGroupBy {
|
||||
iq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &ImageGroupBy{build: iq}
|
||||
grbuild.flds = &iq.ctx.Fields
|
||||
grbuild.label = image.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// URL string `json:"url,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Image.Query().
|
||||
// Select(image.FieldURL).
|
||||
// Scan(ctx, &v)
|
||||
func (iq *ImageQuery) Select(fields ...string) *ImageSelect {
|
||||
iq.ctx.Fields = append(iq.ctx.Fields, fields...)
|
||||
sbuild := &ImageSelect{ImageQuery: iq}
|
||||
sbuild.label = image.Label
|
||||
sbuild.flds, sbuild.scan = &iq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a ImageSelect configured with the given aggregations.
|
||||
func (iq *ImageQuery) Aggregate(fns ...AggregateFunc) *ImageSelect {
|
||||
return iq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (iq *ImageQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range iq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, iq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range iq.ctx.Fields {
|
||||
if !image.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if iq.path != nil {
|
||||
prev, err := iq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
iq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (iq *ImageQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Image, error) {
|
||||
var (
|
||||
nodes = []*Image{}
|
||||
_spec = iq.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Image).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Image{config: iq.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, iq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (iq *ImageQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := iq.querySpec()
|
||||
_spec.Node.Columns = iq.ctx.Fields
|
||||
if len(iq.ctx.Fields) > 0 {
|
||||
_spec.Unique = iq.ctx.Unique != nil && *iq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, iq.driver, _spec)
|
||||
}
|
||||
|
||||
func (iq *ImageQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(image.Table, image.Columns, sqlgraph.NewFieldSpec(image.FieldID, field.TypeInt))
|
||||
_spec.From = iq.sql
|
||||
if unique := iq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if iq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := iq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, image.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != image.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := iq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := iq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := iq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := iq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (iq *ImageQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(iq.driver.Dialect())
|
||||
t1 := builder.Table(image.Table)
|
||||
columns := iq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = image.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if iq.sql != nil {
|
||||
selector = iq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if iq.ctx.Unique != nil && *iq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range iq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range iq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := iq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := iq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ImageGroupBy is the group-by builder for Image entities.
|
||||
type ImageGroupBy struct {
|
||||
selector
|
||||
build *ImageQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (igb *ImageGroupBy) Aggregate(fns ...AggregateFunc) *ImageGroupBy {
|
||||
igb.fns = append(igb.fns, fns...)
|
||||
return igb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (igb *ImageGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, igb.build.ctx, "GroupBy")
|
||||
if err := igb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*ImageQuery, *ImageGroupBy](ctx, igb.build, igb, igb.build.inters, v)
|
||||
}
|
||||
|
||||
func (igb *ImageGroupBy) sqlScan(ctx context.Context, root *ImageQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(igb.fns))
|
||||
for _, fn := range igb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*igb.flds)+len(igb.fns))
|
||||
for _, f := range *igb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*igb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := igb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// ImageSelect is the builder for selecting fields of Image entities.
|
||||
type ImageSelect struct {
|
||||
*ImageQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (is *ImageSelect) Aggregate(fns ...AggregateFunc) *ImageSelect {
|
||||
is.fns = append(is.fns, fns...)
|
||||
return is
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (is *ImageSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, is.ctx, "Select")
|
||||
if err := is.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*ImageQuery, *ImageSelect](ctx, is.ImageQuery, is, is.inters, v)
|
||||
}
|
||||
|
||||
func (is *ImageSelect) sqlScan(ctx context.Context, root *ImageQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(is.fns))
|
||||
for _, fn := range is.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*is.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := is.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
243
ent/image_update.go
Normal file
243
ent/image_update.go
Normal file
|
|
@ -0,0 +1,243 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/lysand-org/versia-go/ent/image"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
)
|
||||
|
||||
// ImageUpdate is the builder for updating Image entities.
|
||||
type ImageUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ImageMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ImageUpdate builder.
|
||||
func (iu *ImageUpdate) Where(ps ...predicate.Image) *ImageUpdate {
|
||||
iu.mutation.Where(ps...)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetURL sets the "url" field.
|
||||
func (iu *ImageUpdate) SetURL(s string) *ImageUpdate {
|
||||
iu.mutation.SetURL(s)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetNillableURL sets the "url" field if the given value is not nil.
|
||||
func (iu *ImageUpdate) SetNillableURL(s *string) *ImageUpdate {
|
||||
if s != nil {
|
||||
iu.SetURL(*s)
|
||||
}
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetMimeType sets the "mimeType" field.
|
||||
func (iu *ImageUpdate) SetMimeType(s string) *ImageUpdate {
|
||||
iu.mutation.SetMimeType(s)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetNillableMimeType sets the "mimeType" field if the given value is not nil.
|
||||
func (iu *ImageUpdate) SetNillableMimeType(s *string) *ImageUpdate {
|
||||
if s != nil {
|
||||
iu.SetMimeType(*s)
|
||||
}
|
||||
return iu
|
||||
}
|
||||
|
||||
// Mutation returns the ImageMutation object of the builder.
|
||||
func (iu *ImageUpdate) Mutation() *ImageMutation {
|
||||
return iu.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (iu *ImageUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, iu.sqlSave, iu.mutation, iu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (iu *ImageUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := iu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (iu *ImageUpdate) Exec(ctx context.Context) error {
|
||||
_, err := iu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (iu *ImageUpdate) ExecX(ctx context.Context) {
|
||||
if err := iu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (iu *ImageUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(image.Table, image.Columns, sqlgraph.NewFieldSpec(image.FieldID, field.TypeInt))
|
||||
if ps := iu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := iu.mutation.URL(); ok {
|
||||
_spec.SetField(image.FieldURL, field.TypeString, value)
|
||||
}
|
||||
if value, ok := iu.mutation.MimeType(); ok {
|
||||
_spec.SetField(image.FieldMimeType, field.TypeString, value)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, iu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{image.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
iu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// ImageUpdateOne is the builder for updating a single Image entity.
|
||||
type ImageUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *ImageMutation
|
||||
}
|
||||
|
||||
// SetURL sets the "url" field.
|
||||
func (iuo *ImageUpdateOne) SetURL(s string) *ImageUpdateOne {
|
||||
iuo.mutation.SetURL(s)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetNillableURL sets the "url" field if the given value is not nil.
|
||||
func (iuo *ImageUpdateOne) SetNillableURL(s *string) *ImageUpdateOne {
|
||||
if s != nil {
|
||||
iuo.SetURL(*s)
|
||||
}
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetMimeType sets the "mimeType" field.
|
||||
func (iuo *ImageUpdateOne) SetMimeType(s string) *ImageUpdateOne {
|
||||
iuo.mutation.SetMimeType(s)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetNillableMimeType sets the "mimeType" field if the given value is not nil.
|
||||
func (iuo *ImageUpdateOne) SetNillableMimeType(s *string) *ImageUpdateOne {
|
||||
if s != nil {
|
||||
iuo.SetMimeType(*s)
|
||||
}
|
||||
return iuo
|
||||
}
|
||||
|
||||
// Mutation returns the ImageMutation object of the builder.
|
||||
func (iuo *ImageUpdateOne) Mutation() *ImageMutation {
|
||||
return iuo.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ImageUpdate builder.
|
||||
func (iuo *ImageUpdateOne) Where(ps ...predicate.Image) *ImageUpdateOne {
|
||||
iuo.mutation.Where(ps...)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (iuo *ImageUpdateOne) Select(field string, fields ...string) *ImageUpdateOne {
|
||||
iuo.fields = append([]string{field}, fields...)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Image entity.
|
||||
func (iuo *ImageUpdateOne) Save(ctx context.Context) (*Image, error) {
|
||||
return withHooks(ctx, iuo.sqlSave, iuo.mutation, iuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (iuo *ImageUpdateOne) SaveX(ctx context.Context) *Image {
|
||||
node, err := iuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (iuo *ImageUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := iuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (iuo *ImageUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := iuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (iuo *ImageUpdateOne) sqlSave(ctx context.Context) (_node *Image, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(image.Table, image.Columns, sqlgraph.NewFieldSpec(image.FieldID, field.TypeInt))
|
||||
id, ok := iuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Image.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := iuo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, image.FieldID)
|
||||
for _, f := range fields {
|
||||
if !image.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != image.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := iuo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := iuo.mutation.URL(); ok {
|
||||
_spec.SetField(image.FieldURL, field.TypeString, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.MimeType(); ok {
|
||||
_spec.SetField(image.FieldMimeType, field.TypeString, value)
|
||||
}
|
||||
_node = &Image{config: iuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, iuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{image.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
iuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
9
ent/internal/schema.go
Normal file
9
ent/internal/schema.go
Normal file
File diff suppressed because one or more lines are too long
64
ent/migrate/migrate.go
Normal file
64
ent/migrate/migrate.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||
// for the ids of each entity (table).
|
||||
// Note that this option cannot be applied on tables that already exist.
|
||||
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||
// WithDropColumn sets the drop column option to the migration.
|
||||
// If this option is enabled, ent migration will drop old columns
|
||||
// that were used for both fields and edges. This defaults to false.
|
||||
WithDropColumn = schema.WithDropColumn
|
||||
// WithDropIndex sets the drop index option to the migration.
|
||||
// If this option is enabled, ent migration will drop old indexes
|
||||
// that were defined in the schema. This defaults to false.
|
||||
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||
// and therefore, it's recommended to enable this option to get more
|
||||
// flexibility in the schema changes.
|
||||
WithDropIndex = schema.WithDropIndex
|
||||
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||
WithForeignKeys = schema.WithForeignKeys
|
||||
)
|
||||
|
||||
// Schema is the API for creating, migrating and dropping a schema.
|
||||
type Schema struct {
|
||||
drv dialect.Driver
|
||||
}
|
||||
|
||||
// NewSchema creates a new schema client.
|
||||
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||
|
||||
// Create creates all schema resources.
|
||||
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||
return Create(ctx, s, Tables, opts...)
|
||||
}
|
||||
|
||||
// Create creates all table resources using the given schema driver.
|
||||
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
|
||||
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %w", err)
|
||||
}
|
||||
return migrate.Create(ctx, tables...)
|
||||
}
|
||||
|
||||
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||
//
|
||||
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
|
||||
}
|
||||
265
ent/migrate/schema.go
Normal file
265
ent/migrate/schema.go
Normal file
|
|
@ -0,0 +1,265 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
var (
|
||||
// AttachmentsColumns holds the columns for the "attachments" table.
|
||||
AttachmentsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID},
|
||||
{Name: "is_remote", Type: field.TypeBool},
|
||||
{Name: "uri", Type: field.TypeString},
|
||||
{Name: "extensions", Type: field.TypeJSON},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "description", Type: field.TypeString, Size: 384},
|
||||
{Name: "sha256", Type: field.TypeBytes},
|
||||
{Name: "size", Type: field.TypeInt},
|
||||
{Name: "blurhash", Type: field.TypeString, Nullable: true},
|
||||
{Name: "height", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "width", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "fps", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "mime_type", Type: field.TypeString},
|
||||
{Name: "attachment_author", Type: field.TypeUUID},
|
||||
{Name: "note_attachments", Type: field.TypeUUID, Nullable: true},
|
||||
}
|
||||
// AttachmentsTable holds the schema information for the "attachments" table.
|
||||
AttachmentsTable = &schema.Table{
|
||||
Name: "attachments",
|
||||
Columns: AttachmentsColumns,
|
||||
PrimaryKey: []*schema.Column{AttachmentsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "attachments_users_author",
|
||||
Columns: []*schema.Column{AttachmentsColumns[14]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
{
|
||||
Symbol: "attachments_notes_attachments",
|
||||
Columns: []*schema.Column{AttachmentsColumns[15]},
|
||||
RefColumns: []*schema.Column{NotesColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// FollowsColumns holds the columns for the "follows" table.
|
||||
FollowsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID},
|
||||
{Name: "is_remote", Type: field.TypeBool},
|
||||
{Name: "uri", Type: field.TypeString},
|
||||
{Name: "extensions", Type: field.TypeJSON},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"pending", "accepted"}, Default: "pending"},
|
||||
{Name: "follow_follower", Type: field.TypeUUID},
|
||||
{Name: "follow_followee", Type: field.TypeUUID},
|
||||
}
|
||||
// FollowsTable holds the schema information for the "follows" table.
|
||||
FollowsTable = &schema.Table{
|
||||
Name: "follows",
|
||||
Columns: FollowsColumns,
|
||||
PrimaryKey: []*schema.Column{FollowsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "follows_users_follower",
|
||||
Columns: []*schema.Column{FollowsColumns[7]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
{
|
||||
Symbol: "follows_users_followee",
|
||||
Columns: []*schema.Column{FollowsColumns[8]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "follow_follow_follower_follow_followee",
|
||||
Unique: true,
|
||||
Columns: []*schema.Column{FollowsColumns[7], FollowsColumns[8]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// ImagesColumns holds the columns for the "images" table.
|
||||
ImagesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "url", Type: field.TypeString},
|
||||
{Name: "mime_type", Type: field.TypeString},
|
||||
}
|
||||
// ImagesTable holds the schema information for the "images" table.
|
||||
ImagesTable = &schema.Table{
|
||||
Name: "images",
|
||||
Columns: ImagesColumns,
|
||||
PrimaryKey: []*schema.Column{ImagesColumns[0]},
|
||||
}
|
||||
// NotesColumns holds the columns for the "notes" table.
|
||||
NotesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID},
|
||||
{Name: "is_remote", Type: field.TypeBool},
|
||||
{Name: "uri", Type: field.TypeString},
|
||||
{Name: "extensions", Type: field.TypeJSON},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "subject", Type: field.TypeString, Nullable: true, Size: 384},
|
||||
{Name: "content", Type: field.TypeString},
|
||||
{Name: "is_sensitive", Type: field.TypeBool, Default: false},
|
||||
{Name: "visibility", Type: field.TypeEnum, Enums: []string{"public", "unlisted", "followers", "direct"}, Default: "public"},
|
||||
{Name: "note_author", Type: field.TypeUUID},
|
||||
}
|
||||
// NotesTable holds the schema information for the "notes" table.
|
||||
NotesTable = &schema.Table{
|
||||
Name: "notes",
|
||||
Columns: NotesColumns,
|
||||
PrimaryKey: []*schema.Column{NotesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "notes_users_author",
|
||||
Columns: []*schema.Column{NotesColumns[10]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
},
|
||||
}
|
||||
// ServerMetadataColumns holds the columns for the "server_metadata" table.
|
||||
ServerMetadataColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID},
|
||||
{Name: "is_remote", Type: field.TypeBool},
|
||||
{Name: "uri", Type: field.TypeString},
|
||||
{Name: "extensions", Type: field.TypeJSON},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
{Name: "description", Type: field.TypeString, Nullable: true},
|
||||
{Name: "version", Type: field.TypeString},
|
||||
{Name: "supported_extensions", Type: field.TypeJSON},
|
||||
{Name: "server_metadata_follower", Type: field.TypeUUID},
|
||||
{Name: "server_metadata_followee", Type: field.TypeUUID},
|
||||
}
|
||||
// ServerMetadataTable holds the schema information for the "server_metadata" table.
|
||||
ServerMetadataTable = &schema.Table{
|
||||
Name: "server_metadata",
|
||||
Columns: ServerMetadataColumns,
|
||||
PrimaryKey: []*schema.Column{ServerMetadataColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "server_metadata_users_follower",
|
||||
Columns: []*schema.Column{ServerMetadataColumns[10]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
{
|
||||
Symbol: "server_metadata_users_followee",
|
||||
Columns: []*schema.Column{ServerMetadataColumns[11]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "servermetadata_server_metadata_follower_server_metadata_followee",
|
||||
Unique: true,
|
||||
Columns: []*schema.Column{ServerMetadataColumns[10], ServerMetadataColumns[11]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// UsersColumns holds the columns for the "users" table.
|
||||
UsersColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID},
|
||||
{Name: "is_remote", Type: field.TypeBool},
|
||||
{Name: "uri", Type: field.TypeString},
|
||||
{Name: "extensions", Type: field.TypeJSON},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "username", Type: field.TypeString, Unique: true, Size: 32},
|
||||
{Name: "password_hash", Type: field.TypeBytes, Nullable: true},
|
||||
{Name: "display_name", Type: field.TypeString, Nullable: true, Size: 256},
|
||||
{Name: "biography", Type: field.TypeString, Nullable: true},
|
||||
{Name: "public_key", Type: field.TypeBytes},
|
||||
{Name: "private_key", Type: field.TypeBytes, Nullable: true},
|
||||
{Name: "indexable", Type: field.TypeBool, Default: true},
|
||||
{Name: "privacy_level", Type: field.TypeEnum, Enums: []string{"public", "restricted", "private"}, Default: "public"},
|
||||
{Name: "fields", Type: field.TypeJSON},
|
||||
{Name: "inbox", Type: field.TypeString},
|
||||
{Name: "featured", Type: field.TypeString},
|
||||
{Name: "followers", Type: field.TypeString},
|
||||
{Name: "following", Type: field.TypeString},
|
||||
{Name: "outbox", Type: field.TypeString},
|
||||
{Name: "user_avatar_image", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "user_header_image", Type: field.TypeInt, Nullable: true},
|
||||
}
|
||||
// UsersTable holds the schema information for the "users" table.
|
||||
UsersTable = &schema.Table{
|
||||
Name: "users",
|
||||
Columns: UsersColumns,
|
||||
PrimaryKey: []*schema.Column{UsersColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "users_images_avatarImage",
|
||||
Columns: []*schema.Column{UsersColumns[20]},
|
||||
RefColumns: []*schema.Column{ImagesColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "users_images_headerImage",
|
||||
Columns: []*schema.Column{UsersColumns[21]},
|
||||
RefColumns: []*schema.Column{ImagesColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// NoteMentionsColumns holds the columns for the "note_mentions" table.
|
||||
NoteMentionsColumns = []*schema.Column{
|
||||
{Name: "note_id", Type: field.TypeUUID},
|
||||
{Name: "user_id", Type: field.TypeUUID},
|
||||
}
|
||||
// NoteMentionsTable holds the schema information for the "note_mentions" table.
|
||||
NoteMentionsTable = &schema.Table{
|
||||
Name: "note_mentions",
|
||||
Columns: NoteMentionsColumns,
|
||||
PrimaryKey: []*schema.Column{NoteMentionsColumns[0], NoteMentionsColumns[1]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "note_mentions_note_id",
|
||||
Columns: []*schema.Column{NoteMentionsColumns[0]},
|
||||
RefColumns: []*schema.Column{NotesColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "note_mentions_user_id",
|
||||
Columns: []*schema.Column{NoteMentionsColumns[1]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
AttachmentsTable,
|
||||
FollowsTable,
|
||||
ImagesTable,
|
||||
NotesTable,
|
||||
ServerMetadataTable,
|
||||
UsersTable,
|
||||
NoteMentionsTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
AttachmentsTable.ForeignKeys[0].RefTable = UsersTable
|
||||
AttachmentsTable.ForeignKeys[1].RefTable = NotesTable
|
||||
FollowsTable.ForeignKeys[0].RefTable = UsersTable
|
||||
FollowsTable.ForeignKeys[1].RefTable = UsersTable
|
||||
NotesTable.ForeignKeys[0].RefTable = UsersTable
|
||||
ServerMetadataTable.ForeignKeys[0].RefTable = UsersTable
|
||||
ServerMetadataTable.ForeignKeys[1].RefTable = UsersTable
|
||||
UsersTable.ForeignKeys[0].RefTable = ImagesTable
|
||||
UsersTable.ForeignKeys[1].RefTable = ImagesTable
|
||||
NoteMentionsTable.ForeignKeys[0].RefTable = NotesTable
|
||||
NoteMentionsTable.ForeignKeys[1].RefTable = UsersTable
|
||||
}
|
||||
6055
ent/mutation.go
Normal file
6055
ent/mutation.go
Normal file
File diff suppressed because it is too large
Load diff
277
ent/note.go
Normal file
277
ent/note.go
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
// Note is the model entity for the Note schema.
|
||||
type Note struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID uuid.UUID `json:"id,omitempty"`
|
||||
// IsRemote holds the value of the "isRemote" field.
|
||||
IsRemote bool `json:"isRemote,omitempty"`
|
||||
// URI holds the value of the "uri" field.
|
||||
URI string `json:"uri,omitempty"`
|
||||
// Extensions holds the value of the "extensions" field.
|
||||
Extensions lysand.Extensions `json:"extensions,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// Subject holds the value of the "subject" field.
|
||||
Subject *string `json:"subject,omitempty"`
|
||||
// Content holds the value of the "content" field.
|
||||
Content string `json:"content,omitempty"`
|
||||
// IsSensitive holds the value of the "isSensitive" field.
|
||||
IsSensitive bool `json:"isSensitive,omitempty"`
|
||||
// Visibility holds the value of the "visibility" field.
|
||||
Visibility note.Visibility `json:"visibility,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the NoteQuery when eager-loading is set.
|
||||
Edges NoteEdges `json:"edges"`
|
||||
note_author *uuid.UUID
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// NoteEdges holds the relations/edges for other nodes in the graph.
|
||||
type NoteEdges struct {
|
||||
// Author holds the value of the author edge.
|
||||
Author *User `json:"author,omitempty"`
|
||||
// Mentions holds the value of the mentions edge.
|
||||
Mentions []*User `json:"mentions,omitempty"`
|
||||
// Attachments holds the value of the attachments edge.
|
||||
Attachments []*Attachment `json:"attachments,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [3]bool
|
||||
}
|
||||
|
||||
// AuthorOrErr returns the Author value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e NoteEdges) AuthorOrErr() (*User, error) {
|
||||
if e.Author != nil {
|
||||
return e.Author, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "author"}
|
||||
}
|
||||
|
||||
// MentionsOrErr returns the Mentions value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e NoteEdges) MentionsOrErr() ([]*User, error) {
|
||||
if e.loadedTypes[1] {
|
||||
return e.Mentions, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "mentions"}
|
||||
}
|
||||
|
||||
// AttachmentsOrErr returns the Attachments value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e NoteEdges) AttachmentsOrErr() ([]*Attachment, error) {
|
||||
if e.loadedTypes[2] {
|
||||
return e.Attachments, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "attachments"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Note) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case note.FieldExtensions:
|
||||
values[i] = new([]byte)
|
||||
case note.FieldIsRemote, note.FieldIsSensitive:
|
||||
values[i] = new(sql.NullBool)
|
||||
case note.FieldURI, note.FieldSubject, note.FieldContent, note.FieldVisibility:
|
||||
values[i] = new(sql.NullString)
|
||||
case note.FieldCreatedAt, note.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
case note.FieldID:
|
||||
values[i] = new(uuid.UUID)
|
||||
case note.ForeignKeys[0]: // note_author
|
||||
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Note fields.
|
||||
func (n *Note) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case note.FieldID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||
} else if value != nil {
|
||||
n.ID = *value
|
||||
}
|
||||
case note.FieldIsRemote:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field isRemote", values[i])
|
||||
} else if value.Valid {
|
||||
n.IsRemote = value.Bool
|
||||
}
|
||||
case note.FieldURI:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uri", values[i])
|
||||
} else if value.Valid {
|
||||
n.URI = value.String
|
||||
}
|
||||
case note.FieldExtensions:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field extensions", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &n.Extensions); err != nil {
|
||||
return fmt.Errorf("unmarshal field extensions: %w", err)
|
||||
}
|
||||
}
|
||||
case note.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
n.CreatedAt = value.Time
|
||||
}
|
||||
case note.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
n.UpdatedAt = value.Time
|
||||
}
|
||||
case note.FieldSubject:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field subject", values[i])
|
||||
} else if value.Valid {
|
||||
n.Subject = new(string)
|
||||
*n.Subject = value.String
|
||||
}
|
||||
case note.FieldContent:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field content", values[i])
|
||||
} else if value.Valid {
|
||||
n.Content = value.String
|
||||
}
|
||||
case note.FieldIsSensitive:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field isSensitive", values[i])
|
||||
} else if value.Valid {
|
||||
n.IsSensitive = value.Bool
|
||||
}
|
||||
case note.FieldVisibility:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field visibility", values[i])
|
||||
} else if value.Valid {
|
||||
n.Visibility = note.Visibility(value.String)
|
||||
}
|
||||
case note.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullScanner); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field note_author", values[i])
|
||||
} else if value.Valid {
|
||||
n.note_author = new(uuid.UUID)
|
||||
*n.note_author = *value.S.(*uuid.UUID)
|
||||
}
|
||||
default:
|
||||
n.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Note.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (n *Note) Value(name string) (ent.Value, error) {
|
||||
return n.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryAuthor queries the "author" edge of the Note entity.
|
||||
func (n *Note) QueryAuthor() *UserQuery {
|
||||
return NewNoteClient(n.config).QueryAuthor(n)
|
||||
}
|
||||
|
||||
// QueryMentions queries the "mentions" edge of the Note entity.
|
||||
func (n *Note) QueryMentions() *UserQuery {
|
||||
return NewNoteClient(n.config).QueryMentions(n)
|
||||
}
|
||||
|
||||
// QueryAttachments queries the "attachments" edge of the Note entity.
|
||||
func (n *Note) QueryAttachments() *AttachmentQuery {
|
||||
return NewNoteClient(n.config).QueryAttachments(n)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Note.
|
||||
// Note that you need to call Note.Unwrap() before calling this method if this Note
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (n *Note) Update() *NoteUpdateOne {
|
||||
return NewNoteClient(n.config).UpdateOne(n)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Note entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (n *Note) Unwrap() *Note {
|
||||
_tx, ok := n.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Note is not a transactional entity")
|
||||
}
|
||||
n.config.driver = _tx.drv
|
||||
return n
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (n *Note) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Note(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", n.ID))
|
||||
builder.WriteString("isRemote=")
|
||||
builder.WriteString(fmt.Sprintf("%v", n.IsRemote))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uri=")
|
||||
builder.WriteString(n.URI)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("extensions=")
|
||||
builder.WriteString(fmt.Sprintf("%v", n.Extensions))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(n.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(n.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
if v := n.Subject; v != nil {
|
||||
builder.WriteString("subject=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("content=")
|
||||
builder.WriteString(n.Content)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("isSensitive=")
|
||||
builder.WriteString(fmt.Sprintf("%v", n.IsSensitive))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("visibility=")
|
||||
builder.WriteString(fmt.Sprintf("%v", n.Visibility))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Notes is a parsable slice of Note.
|
||||
type Notes []*Note
|
||||
257
ent/note/note.go
Normal file
257
ent/note/note.go
Normal file
|
|
@ -0,0 +1,257 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package note
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the note type in the database.
|
||||
Label = "note"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldIsRemote holds the string denoting the isremote field in the database.
|
||||
FieldIsRemote = "is_remote"
|
||||
// FieldURI holds the string denoting the uri field in the database.
|
||||
FieldURI = "uri"
|
||||
// FieldExtensions holds the string denoting the extensions field in the database.
|
||||
FieldExtensions = "extensions"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldSubject holds the string denoting the subject field in the database.
|
||||
FieldSubject = "subject"
|
||||
// FieldContent holds the string denoting the content field in the database.
|
||||
FieldContent = "content"
|
||||
// FieldIsSensitive holds the string denoting the issensitive field in the database.
|
||||
FieldIsSensitive = "is_sensitive"
|
||||
// FieldVisibility holds the string denoting the visibility field in the database.
|
||||
FieldVisibility = "visibility"
|
||||
// EdgeAuthor holds the string denoting the author edge name in mutations.
|
||||
EdgeAuthor = "author"
|
||||
// EdgeMentions holds the string denoting the mentions edge name in mutations.
|
||||
EdgeMentions = "mentions"
|
||||
// EdgeAttachments holds the string denoting the attachments edge name in mutations.
|
||||
EdgeAttachments = "attachments"
|
||||
// Table holds the table name of the note in the database.
|
||||
Table = "notes"
|
||||
// AuthorTable is the table that holds the author relation/edge.
|
||||
AuthorTable = "notes"
|
||||
// AuthorInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
AuthorInverseTable = "users"
|
||||
// AuthorColumn is the table column denoting the author relation/edge.
|
||||
AuthorColumn = "note_author"
|
||||
// MentionsTable is the table that holds the mentions relation/edge. The primary key declared below.
|
||||
MentionsTable = "note_mentions"
|
||||
// MentionsInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
MentionsInverseTable = "users"
|
||||
// AttachmentsTable is the table that holds the attachments relation/edge.
|
||||
AttachmentsTable = "attachments"
|
||||
// AttachmentsInverseTable is the table name for the Attachment entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "attachment" package.
|
||||
AttachmentsInverseTable = "attachments"
|
||||
// AttachmentsColumn is the table column denoting the attachments relation/edge.
|
||||
AttachmentsColumn = "note_attachments"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for note fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldIsRemote,
|
||||
FieldURI,
|
||||
FieldExtensions,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldSubject,
|
||||
FieldContent,
|
||||
FieldIsSensitive,
|
||||
FieldVisibility,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "notes"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"note_author",
|
||||
}
|
||||
|
||||
var (
|
||||
// MentionsPrimaryKey and MentionsColumn2 are the table columns denoting the
|
||||
// primary key for the mentions relation (M2M).
|
||||
MentionsPrimaryKey = []string{"note_id", "user_id"}
|
||||
)
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
URIValidator func(string) error
|
||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
||||
DefaultExtensions lysand.Extensions
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time
|
||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||
UpdateDefaultUpdatedAt func() time.Time
|
||||
// SubjectValidator is a validator for the "subject" field. It is called by the builders before save.
|
||||
SubjectValidator func(string) error
|
||||
// DefaultIsSensitive holds the default value on creation for the "isSensitive" field.
|
||||
DefaultIsSensitive bool
|
||||
// DefaultID holds the default value on creation for the "id" field.
|
||||
DefaultID func() uuid.UUID
|
||||
)
|
||||
|
||||
// Visibility defines the type for the "visibility" enum field.
|
||||
type Visibility string
|
||||
|
||||
// VisibilityPublic is the default value of the Visibility enum.
|
||||
const DefaultVisibility = VisibilityPublic
|
||||
|
||||
// Visibility values.
|
||||
const (
|
||||
VisibilityPublic Visibility = "public"
|
||||
VisibilityUnlisted Visibility = "unlisted"
|
||||
VisibilityFollowers Visibility = "followers"
|
||||
VisibilityDirect Visibility = "direct"
|
||||
)
|
||||
|
||||
func (v Visibility) String() string {
|
||||
return string(v)
|
||||
}
|
||||
|
||||
// VisibilityValidator is a validator for the "visibility" field enum values. It is called by the builders before save.
|
||||
func VisibilityValidator(v Visibility) error {
|
||||
switch v {
|
||||
case VisibilityPublic, VisibilityUnlisted, VisibilityFollowers, VisibilityDirect:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("note: invalid enum value for visibility field: %q", v)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the Note queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByIsRemote orders the results by the isRemote field.
|
||||
func ByIsRemote(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldIsRemote, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByURI orders the results by the uri field.
|
||||
func ByURI(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldURI, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// BySubject orders the results by the subject field.
|
||||
func BySubject(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSubject, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByContent orders the results by the content field.
|
||||
func ByContent(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldContent, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByIsSensitive orders the results by the isSensitive field.
|
||||
func ByIsSensitive(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldIsSensitive, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByVisibility orders the results by the visibility field.
|
||||
func ByVisibility(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldVisibility, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAuthorField orders the results by author field.
|
||||
func ByAuthorField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newAuthorStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByMentionsCount orders the results by mentions count.
|
||||
func ByMentionsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newMentionsStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByMentions orders the results by mentions terms.
|
||||
func ByMentions(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newMentionsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByAttachmentsCount orders the results by attachments count.
|
||||
func ByAttachmentsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newAttachmentsStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByAttachments orders the results by attachments terms.
|
||||
func ByAttachments(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newAttachmentsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newAuthorStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(AuthorInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, AuthorTable, AuthorColumn),
|
||||
)
|
||||
}
|
||||
func newMentionsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(MentionsInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, MentionsTable, MentionsPrimaryKey...),
|
||||
)
|
||||
}
|
||||
func newAttachmentsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(AttachmentsInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, AttachmentsTable, AttachmentsColumn),
|
||||
)
|
||||
}
|
||||
501
ent/note/where.go
Normal file
501
ent/note/where.go
Normal file
|
|
@ -0,0 +1,501 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package note
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id uuid.UUID) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id uuid.UUID) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id uuid.UUID) predicate.Note {
|
||||
return predicate.Note(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...uuid.UUID) predicate.Note {
|
||||
return predicate.Note(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...uuid.UUID) predicate.Note {
|
||||
return predicate.Note(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id uuid.UUID) predicate.Note {
|
||||
return predicate.Note(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id uuid.UUID) predicate.Note {
|
||||
return predicate.Note(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id uuid.UUID) predicate.Note {
|
||||
return predicate.Note(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id uuid.UUID) predicate.Note {
|
||||
return predicate.Note(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IsRemote applies equality check predicate on the "isRemote" field. It's identical to IsRemoteEQ.
|
||||
func IsRemote(v bool) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldIsRemote, v))
|
||||
}
|
||||
|
||||
// URI applies equality check predicate on the "uri" field. It's identical to URIEQ.
|
||||
func URI(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldURI, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// Subject applies equality check predicate on the "subject" field. It's identical to SubjectEQ.
|
||||
func Subject(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldSubject, v))
|
||||
}
|
||||
|
||||
// Content applies equality check predicate on the "content" field. It's identical to ContentEQ.
|
||||
func Content(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldContent, v))
|
||||
}
|
||||
|
||||
// IsSensitive applies equality check predicate on the "isSensitive" field. It's identical to IsSensitiveEQ.
|
||||
func IsSensitive(v bool) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldIsSensitive, v))
|
||||
}
|
||||
|
||||
// IsRemoteEQ applies the EQ predicate on the "isRemote" field.
|
||||
func IsRemoteEQ(v bool) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldIsRemote, v))
|
||||
}
|
||||
|
||||
// IsRemoteNEQ applies the NEQ predicate on the "isRemote" field.
|
||||
func IsRemoteNEQ(v bool) predicate.Note {
|
||||
return predicate.Note(sql.FieldNEQ(FieldIsRemote, v))
|
||||
}
|
||||
|
||||
// URIEQ applies the EQ predicate on the "uri" field.
|
||||
func URIEQ(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldURI, v))
|
||||
}
|
||||
|
||||
// URINEQ applies the NEQ predicate on the "uri" field.
|
||||
func URINEQ(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldNEQ(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIIn applies the In predicate on the "uri" field.
|
||||
func URIIn(vs ...string) predicate.Note {
|
||||
return predicate.Note(sql.FieldIn(FieldURI, vs...))
|
||||
}
|
||||
|
||||
// URINotIn applies the NotIn predicate on the "uri" field.
|
||||
func URINotIn(vs ...string) predicate.Note {
|
||||
return predicate.Note(sql.FieldNotIn(FieldURI, vs...))
|
||||
}
|
||||
|
||||
// URIGT applies the GT predicate on the "uri" field.
|
||||
func URIGT(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldGT(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIGTE applies the GTE predicate on the "uri" field.
|
||||
func URIGTE(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldGTE(FieldURI, v))
|
||||
}
|
||||
|
||||
// URILT applies the LT predicate on the "uri" field.
|
||||
func URILT(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldLT(FieldURI, v))
|
||||
}
|
||||
|
||||
// URILTE applies the LTE predicate on the "uri" field.
|
||||
func URILTE(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldLTE(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIContains applies the Contains predicate on the "uri" field.
|
||||
func URIContains(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldContains(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIHasPrefix applies the HasPrefix predicate on the "uri" field.
|
||||
func URIHasPrefix(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldHasPrefix(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIHasSuffix applies the HasSuffix predicate on the "uri" field.
|
||||
func URIHasSuffix(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldHasSuffix(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIEqualFold applies the EqualFold predicate on the "uri" field.
|
||||
func URIEqualFold(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldEqualFold(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIContainsFold applies the ContainsFold predicate on the "uri" field.
|
||||
func URIContainsFold(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldContainsFold(FieldURI, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldGT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldGTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldLT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.Note {
|
||||
return predicate.Note(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// SubjectEQ applies the EQ predicate on the "subject" field.
|
||||
func SubjectEQ(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldSubject, v))
|
||||
}
|
||||
|
||||
// SubjectNEQ applies the NEQ predicate on the "subject" field.
|
||||
func SubjectNEQ(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldNEQ(FieldSubject, v))
|
||||
}
|
||||
|
||||
// SubjectIn applies the In predicate on the "subject" field.
|
||||
func SubjectIn(vs ...string) predicate.Note {
|
||||
return predicate.Note(sql.FieldIn(FieldSubject, vs...))
|
||||
}
|
||||
|
||||
// SubjectNotIn applies the NotIn predicate on the "subject" field.
|
||||
func SubjectNotIn(vs ...string) predicate.Note {
|
||||
return predicate.Note(sql.FieldNotIn(FieldSubject, vs...))
|
||||
}
|
||||
|
||||
// SubjectGT applies the GT predicate on the "subject" field.
|
||||
func SubjectGT(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldGT(FieldSubject, v))
|
||||
}
|
||||
|
||||
// SubjectGTE applies the GTE predicate on the "subject" field.
|
||||
func SubjectGTE(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldGTE(FieldSubject, v))
|
||||
}
|
||||
|
||||
// SubjectLT applies the LT predicate on the "subject" field.
|
||||
func SubjectLT(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldLT(FieldSubject, v))
|
||||
}
|
||||
|
||||
// SubjectLTE applies the LTE predicate on the "subject" field.
|
||||
func SubjectLTE(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldLTE(FieldSubject, v))
|
||||
}
|
||||
|
||||
// SubjectContains applies the Contains predicate on the "subject" field.
|
||||
func SubjectContains(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldContains(FieldSubject, v))
|
||||
}
|
||||
|
||||
// SubjectHasPrefix applies the HasPrefix predicate on the "subject" field.
|
||||
func SubjectHasPrefix(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldHasPrefix(FieldSubject, v))
|
||||
}
|
||||
|
||||
// SubjectHasSuffix applies the HasSuffix predicate on the "subject" field.
|
||||
func SubjectHasSuffix(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldHasSuffix(FieldSubject, v))
|
||||
}
|
||||
|
||||
// SubjectIsNil applies the IsNil predicate on the "subject" field.
|
||||
func SubjectIsNil() predicate.Note {
|
||||
return predicate.Note(sql.FieldIsNull(FieldSubject))
|
||||
}
|
||||
|
||||
// SubjectNotNil applies the NotNil predicate on the "subject" field.
|
||||
func SubjectNotNil() predicate.Note {
|
||||
return predicate.Note(sql.FieldNotNull(FieldSubject))
|
||||
}
|
||||
|
||||
// SubjectEqualFold applies the EqualFold predicate on the "subject" field.
|
||||
func SubjectEqualFold(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldEqualFold(FieldSubject, v))
|
||||
}
|
||||
|
||||
// SubjectContainsFold applies the ContainsFold predicate on the "subject" field.
|
||||
func SubjectContainsFold(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldContainsFold(FieldSubject, v))
|
||||
}
|
||||
|
||||
// ContentEQ applies the EQ predicate on the "content" field.
|
||||
func ContentEQ(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentNEQ applies the NEQ predicate on the "content" field.
|
||||
func ContentNEQ(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldNEQ(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentIn applies the In predicate on the "content" field.
|
||||
func ContentIn(vs ...string) predicate.Note {
|
||||
return predicate.Note(sql.FieldIn(FieldContent, vs...))
|
||||
}
|
||||
|
||||
// ContentNotIn applies the NotIn predicate on the "content" field.
|
||||
func ContentNotIn(vs ...string) predicate.Note {
|
||||
return predicate.Note(sql.FieldNotIn(FieldContent, vs...))
|
||||
}
|
||||
|
||||
// ContentGT applies the GT predicate on the "content" field.
|
||||
func ContentGT(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldGT(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentGTE applies the GTE predicate on the "content" field.
|
||||
func ContentGTE(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldGTE(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentLT applies the LT predicate on the "content" field.
|
||||
func ContentLT(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldLT(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentLTE applies the LTE predicate on the "content" field.
|
||||
func ContentLTE(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldLTE(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentContains applies the Contains predicate on the "content" field.
|
||||
func ContentContains(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldContains(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentHasPrefix applies the HasPrefix predicate on the "content" field.
|
||||
func ContentHasPrefix(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldHasPrefix(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentHasSuffix applies the HasSuffix predicate on the "content" field.
|
||||
func ContentHasSuffix(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldHasSuffix(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentEqualFold applies the EqualFold predicate on the "content" field.
|
||||
func ContentEqualFold(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldEqualFold(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentContainsFold applies the ContainsFold predicate on the "content" field.
|
||||
func ContentContainsFold(v string) predicate.Note {
|
||||
return predicate.Note(sql.FieldContainsFold(FieldContent, v))
|
||||
}
|
||||
|
||||
// IsSensitiveEQ applies the EQ predicate on the "isSensitive" field.
|
||||
func IsSensitiveEQ(v bool) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldIsSensitive, v))
|
||||
}
|
||||
|
||||
// IsSensitiveNEQ applies the NEQ predicate on the "isSensitive" field.
|
||||
func IsSensitiveNEQ(v bool) predicate.Note {
|
||||
return predicate.Note(sql.FieldNEQ(FieldIsSensitive, v))
|
||||
}
|
||||
|
||||
// VisibilityEQ applies the EQ predicate on the "visibility" field.
|
||||
func VisibilityEQ(v Visibility) predicate.Note {
|
||||
return predicate.Note(sql.FieldEQ(FieldVisibility, v))
|
||||
}
|
||||
|
||||
// VisibilityNEQ applies the NEQ predicate on the "visibility" field.
|
||||
func VisibilityNEQ(v Visibility) predicate.Note {
|
||||
return predicate.Note(sql.FieldNEQ(FieldVisibility, v))
|
||||
}
|
||||
|
||||
// VisibilityIn applies the In predicate on the "visibility" field.
|
||||
func VisibilityIn(vs ...Visibility) predicate.Note {
|
||||
return predicate.Note(sql.FieldIn(FieldVisibility, vs...))
|
||||
}
|
||||
|
||||
// VisibilityNotIn applies the NotIn predicate on the "visibility" field.
|
||||
func VisibilityNotIn(vs ...Visibility) predicate.Note {
|
||||
return predicate.Note(sql.FieldNotIn(FieldVisibility, vs...))
|
||||
}
|
||||
|
||||
// HasAuthor applies the HasEdge predicate on the "author" edge.
|
||||
func HasAuthor() predicate.Note {
|
||||
return predicate.Note(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, AuthorTable, AuthorColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasAuthorWith applies the HasEdge predicate on the "author" edge with a given conditions (other predicates).
|
||||
func HasAuthorWith(preds ...predicate.User) predicate.Note {
|
||||
return predicate.Note(func(s *sql.Selector) {
|
||||
step := newAuthorStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasMentions applies the HasEdge predicate on the "mentions" edge.
|
||||
func HasMentions() predicate.Note {
|
||||
return predicate.Note(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, MentionsTable, MentionsPrimaryKey...),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasMentionsWith applies the HasEdge predicate on the "mentions" edge with a given conditions (other predicates).
|
||||
func HasMentionsWith(preds ...predicate.User) predicate.Note {
|
||||
return predicate.Note(func(s *sql.Selector) {
|
||||
step := newMentionsStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasAttachments applies the HasEdge predicate on the "attachments" edge.
|
||||
func HasAttachments() predicate.Note {
|
||||
return predicate.Note(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, AttachmentsTable, AttachmentsColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasAttachmentsWith applies the HasEdge predicate on the "attachments" edge with a given conditions (other predicates).
|
||||
func HasAttachmentsWith(preds ...predicate.Attachment) predicate.Note {
|
||||
return predicate.Note(func(s *sql.Selector) {
|
||||
step := newAttachmentsStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Note) predicate.Note {
|
||||
return predicate.Note(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Note) predicate.Note {
|
||||
return predicate.Note(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Note) predicate.Note {
|
||||
return predicate.Note(sql.NotPredicates(p))
|
||||
}
|
||||
1087
ent/note_create.go
Normal file
1087
ent/note_create.go
Normal file
File diff suppressed because it is too large
Load diff
88
ent/note_delete.go
Normal file
88
ent/note_delete.go
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
)
|
||||
|
||||
// NoteDelete is the builder for deleting a Note entity.
|
||||
type NoteDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *NoteMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NoteDelete builder.
|
||||
func (nd *NoteDelete) Where(ps ...predicate.Note) *NoteDelete {
|
||||
nd.mutation.Where(ps...)
|
||||
return nd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (nd *NoteDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, nd.sqlExec, nd.mutation, nd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (nd *NoteDelete) ExecX(ctx context.Context) int {
|
||||
n, err := nd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (nd *NoteDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(note.Table, sqlgraph.NewFieldSpec(note.FieldID, field.TypeUUID))
|
||||
if ps := nd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, nd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
nd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// NoteDeleteOne is the builder for deleting a single Note entity.
|
||||
type NoteDeleteOne struct {
|
||||
nd *NoteDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NoteDelete builder.
|
||||
func (ndo *NoteDeleteOne) Where(ps ...predicate.Note) *NoteDeleteOne {
|
||||
ndo.nd.mutation.Where(ps...)
|
||||
return ndo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (ndo *NoteDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := ndo.nd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{note.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ndo *NoteDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := ndo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
794
ent/note_query.go
Normal file
794
ent/note_query.go
Normal file
|
|
@ -0,0 +1,794 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/attachment"
|
||||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
)
|
||||
|
||||
// NoteQuery is the builder for querying Note entities.
|
||||
type NoteQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []note.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Note
|
||||
withAuthor *UserQuery
|
||||
withMentions *UserQuery
|
||||
withAttachments *AttachmentQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the NoteQuery builder.
|
||||
func (nq *NoteQuery) Where(ps ...predicate.Note) *NoteQuery {
|
||||
nq.predicates = append(nq.predicates, ps...)
|
||||
return nq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (nq *NoteQuery) Limit(limit int) *NoteQuery {
|
||||
nq.ctx.Limit = &limit
|
||||
return nq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (nq *NoteQuery) Offset(offset int) *NoteQuery {
|
||||
nq.ctx.Offset = &offset
|
||||
return nq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (nq *NoteQuery) Unique(unique bool) *NoteQuery {
|
||||
nq.ctx.Unique = &unique
|
||||
return nq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (nq *NoteQuery) Order(o ...note.OrderOption) *NoteQuery {
|
||||
nq.order = append(nq.order, o...)
|
||||
return nq
|
||||
}
|
||||
|
||||
// QueryAuthor chains the current query on the "author" edge.
|
||||
func (nq *NoteQuery) QueryAuthor() *UserQuery {
|
||||
query := (&UserClient{config: nq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := nq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := nq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(note.Table, note.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, note.AuthorTable, note.AuthorColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(nq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryMentions chains the current query on the "mentions" edge.
|
||||
func (nq *NoteQuery) QueryMentions() *UserQuery {
|
||||
query := (&UserClient{config: nq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := nq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := nq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(note.Table, note.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, note.MentionsTable, note.MentionsPrimaryKey...),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(nq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryAttachments chains the current query on the "attachments" edge.
|
||||
func (nq *NoteQuery) QueryAttachments() *AttachmentQuery {
|
||||
query := (&AttachmentClient{config: nq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := nq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := nq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(note.Table, note.FieldID, selector),
|
||||
sqlgraph.To(attachment.Table, attachment.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, note.AttachmentsTable, note.AttachmentsColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(nq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Note entity from the query.
|
||||
// Returns a *NotFoundError when no Note was found.
|
||||
func (nq *NoteQuery) First(ctx context.Context) (*Note, error) {
|
||||
nodes, err := nq.Limit(1).All(setContextOp(ctx, nq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{note.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (nq *NoteQuery) FirstX(ctx context.Context) *Note {
|
||||
node, err := nq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Note ID from the query.
|
||||
// Returns a *NotFoundError when no Note ID was found.
|
||||
func (nq *NoteQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = nq.Limit(1).IDs(setContextOp(ctx, nq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{note.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (nq *NoteQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := nq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Note entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Note entity is found.
|
||||
// Returns a *NotFoundError when no Note entities are found.
|
||||
func (nq *NoteQuery) Only(ctx context.Context) (*Note, error) {
|
||||
nodes, err := nq.Limit(2).All(setContextOp(ctx, nq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{note.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{note.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (nq *NoteQuery) OnlyX(ctx context.Context) *Note {
|
||||
node, err := nq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Note ID in the query.
|
||||
// Returns a *NotSingularError when more than one Note ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (nq *NoteQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = nq.Limit(2).IDs(setContextOp(ctx, nq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{note.Label}
|
||||
default:
|
||||
err = &NotSingularError{note.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (nq *NoteQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := nq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Notes.
|
||||
func (nq *NoteQuery) All(ctx context.Context) ([]*Note, error) {
|
||||
ctx = setContextOp(ctx, nq.ctx, "All")
|
||||
if err := nq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Note, *NoteQuery]()
|
||||
return withInterceptors[[]*Note](ctx, nq, qr, nq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (nq *NoteQuery) AllX(ctx context.Context) []*Note {
|
||||
nodes, err := nq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Note IDs.
|
||||
func (nq *NoteQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||
if nq.ctx.Unique == nil && nq.path != nil {
|
||||
nq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, nq.ctx, "IDs")
|
||||
if err = nq.Select(note.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (nq *NoteQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||
ids, err := nq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (nq *NoteQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, nq.ctx, "Count")
|
||||
if err := nq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, nq, querierCount[*NoteQuery](), nq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (nq *NoteQuery) CountX(ctx context.Context) int {
|
||||
count, err := nq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (nq *NoteQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, nq.ctx, "Exist")
|
||||
switch _, err := nq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (nq *NoteQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := nq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the NoteQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (nq *NoteQuery) Clone() *NoteQuery {
|
||||
if nq == nil {
|
||||
return nil
|
||||
}
|
||||
return &NoteQuery{
|
||||
config: nq.config,
|
||||
ctx: nq.ctx.Clone(),
|
||||
order: append([]note.OrderOption{}, nq.order...),
|
||||
inters: append([]Interceptor{}, nq.inters...),
|
||||
predicates: append([]predicate.Note{}, nq.predicates...),
|
||||
withAuthor: nq.withAuthor.Clone(),
|
||||
withMentions: nq.withMentions.Clone(),
|
||||
withAttachments: nq.withAttachments.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: nq.sql.Clone(),
|
||||
path: nq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithAuthor tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "author" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (nq *NoteQuery) WithAuthor(opts ...func(*UserQuery)) *NoteQuery {
|
||||
query := (&UserClient{config: nq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
nq.withAuthor = query
|
||||
return nq
|
||||
}
|
||||
|
||||
// WithMentions tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "mentions" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (nq *NoteQuery) WithMentions(opts ...func(*UserQuery)) *NoteQuery {
|
||||
query := (&UserClient{config: nq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
nq.withMentions = query
|
||||
return nq
|
||||
}
|
||||
|
||||
// WithAttachments tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "attachments" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (nq *NoteQuery) WithAttachments(opts ...func(*AttachmentQuery)) *NoteQuery {
|
||||
query := (&AttachmentClient{config: nq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
nq.withAttachments = query
|
||||
return nq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// IsRemote bool `json:"isRemote,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Note.Query().
|
||||
// GroupBy(note.FieldIsRemote).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (nq *NoteQuery) GroupBy(field string, fields ...string) *NoteGroupBy {
|
||||
nq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &NoteGroupBy{build: nq}
|
||||
grbuild.flds = &nq.ctx.Fields
|
||||
grbuild.label = note.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// IsRemote bool `json:"isRemote,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Note.Query().
|
||||
// Select(note.FieldIsRemote).
|
||||
// Scan(ctx, &v)
|
||||
func (nq *NoteQuery) Select(fields ...string) *NoteSelect {
|
||||
nq.ctx.Fields = append(nq.ctx.Fields, fields...)
|
||||
sbuild := &NoteSelect{NoteQuery: nq}
|
||||
sbuild.label = note.Label
|
||||
sbuild.flds, sbuild.scan = &nq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a NoteSelect configured with the given aggregations.
|
||||
func (nq *NoteQuery) Aggregate(fns ...AggregateFunc) *NoteSelect {
|
||||
return nq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (nq *NoteQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range nq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, nq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range nq.ctx.Fields {
|
||||
if !note.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if nq.path != nil {
|
||||
prev, err := nq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nq *NoteQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Note, error) {
|
||||
var (
|
||||
nodes = []*Note{}
|
||||
withFKs = nq.withFKs
|
||||
_spec = nq.querySpec()
|
||||
loadedTypes = [3]bool{
|
||||
nq.withAuthor != nil,
|
||||
nq.withMentions != nil,
|
||||
nq.withAttachments != nil,
|
||||
}
|
||||
)
|
||||
if nq.withAuthor != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, note.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Note).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Note{config: nq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, nq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := nq.withAuthor; query != nil {
|
||||
if err := nq.loadAuthor(ctx, query, nodes, nil,
|
||||
func(n *Note, e *User) { n.Edges.Author = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := nq.withMentions; query != nil {
|
||||
if err := nq.loadMentions(ctx, query, nodes,
|
||||
func(n *Note) { n.Edges.Mentions = []*User{} },
|
||||
func(n *Note, e *User) { n.Edges.Mentions = append(n.Edges.Mentions, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := nq.withAttachments; query != nil {
|
||||
if err := nq.loadAttachments(ctx, query, nodes,
|
||||
func(n *Note) { n.Edges.Attachments = []*Attachment{} },
|
||||
func(n *Note, e *Attachment) { n.Edges.Attachments = append(n.Edges.Attachments, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (nq *NoteQuery) loadAuthor(ctx context.Context, query *UserQuery, nodes []*Note, init func(*Note), assign func(*Note, *User)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*Note)
|
||||
for i := range nodes {
|
||||
if nodes[i].note_author == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].note_author
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "note_author" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (nq *NoteQuery) loadMentions(ctx context.Context, query *UserQuery, nodes []*Note, init func(*Note), assign func(*Note, *User)) error {
|
||||
edgeIDs := make([]driver.Value, len(nodes))
|
||||
byID := make(map[uuid.UUID]*Note)
|
||||
nids := make(map[uuid.UUID]map[*Note]struct{})
|
||||
for i, node := range nodes {
|
||||
edgeIDs[i] = node.ID
|
||||
byID[node.ID] = node
|
||||
if init != nil {
|
||||
init(node)
|
||||
}
|
||||
}
|
||||
query.Where(func(s *sql.Selector) {
|
||||
joinT := sql.Table(note.MentionsTable)
|
||||
s.Join(joinT).On(s.C(user.FieldID), joinT.C(note.MentionsPrimaryKey[1]))
|
||||
s.Where(sql.InValues(joinT.C(note.MentionsPrimaryKey[0]), edgeIDs...))
|
||||
columns := s.SelectedColumns()
|
||||
s.Select(joinT.C(note.MentionsPrimaryKey[0]))
|
||||
s.AppendSelect(columns...)
|
||||
s.SetDistinct(false)
|
||||
})
|
||||
if err := query.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||
assign := spec.Assign
|
||||
values := spec.ScanValues
|
||||
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
values, err := values(columns[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append([]any{new(uuid.UUID)}, values...), nil
|
||||
}
|
||||
spec.Assign = func(columns []string, values []any) error {
|
||||
outValue := *values[0].(*uuid.UUID)
|
||||
inValue := *values[1].(*uuid.UUID)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*Note]struct{}{byID[outValue]: {}}
|
||||
return assign(columns[1:], values[1:])
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
return nil
|
||||
}
|
||||
})
|
||||
})
|
||||
neighbors, err := withInterceptors[[]*User](ctx, query, qr, query.inters)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected "mentions" node returned %v`, n.ID)
|
||||
}
|
||||
for kn := range nodes {
|
||||
assign(kn, n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (nq *NoteQuery) loadAttachments(ctx context.Context, query *AttachmentQuery, nodes []*Note, init func(*Note), assign func(*Note, *Attachment)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID]*Note)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.Attachment(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(note.AttachmentsColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.note_attachments
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "note_attachments" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "note_attachments" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nq *NoteQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := nq.querySpec()
|
||||
_spec.Node.Columns = nq.ctx.Fields
|
||||
if len(nq.ctx.Fields) > 0 {
|
||||
_spec.Unique = nq.ctx.Unique != nil && *nq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, nq.driver, _spec)
|
||||
}
|
||||
|
||||
func (nq *NoteQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(note.Table, note.Columns, sqlgraph.NewFieldSpec(note.FieldID, field.TypeUUID))
|
||||
_spec.From = nq.sql
|
||||
if unique := nq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if nq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := nq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, note.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != note.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := nq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := nq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := nq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := nq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (nq *NoteQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(nq.driver.Dialect())
|
||||
t1 := builder.Table(note.Table)
|
||||
columns := nq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = note.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if nq.sql != nil {
|
||||
selector = nq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if nq.ctx.Unique != nil && *nq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range nq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range nq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := nq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := nq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// NoteGroupBy is the group-by builder for Note entities.
|
||||
type NoteGroupBy struct {
|
||||
selector
|
||||
build *NoteQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (ngb *NoteGroupBy) Aggregate(fns ...AggregateFunc) *NoteGroupBy {
|
||||
ngb.fns = append(ngb.fns, fns...)
|
||||
return ngb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ngb *NoteGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ngb.build.ctx, "GroupBy")
|
||||
if err := ngb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*NoteQuery, *NoteGroupBy](ctx, ngb.build, ngb, ngb.build.inters, v)
|
||||
}
|
||||
|
||||
func (ngb *NoteGroupBy) sqlScan(ctx context.Context, root *NoteQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(ngb.fns))
|
||||
for _, fn := range ngb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*ngb.flds)+len(ngb.fns))
|
||||
for _, f := range *ngb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*ngb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ngb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// NoteSelect is the builder for selecting fields of Note entities.
|
||||
type NoteSelect struct {
|
||||
*NoteQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ns *NoteSelect) Aggregate(fns ...AggregateFunc) *NoteSelect {
|
||||
ns.fns = append(ns.fns, fns...)
|
||||
return ns
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ns *NoteSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ns.ctx, "Select")
|
||||
if err := ns.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*NoteQuery, *NoteSelect](ctx, ns.NoteQuery, ns, ns.inters, v)
|
||||
}
|
||||
|
||||
func (ns *NoteSelect) sqlScan(ctx context.Context, root *NoteQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ns.fns))
|
||||
for _, fn := range ns.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ns.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ns.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
924
ent/note_update.go
Normal file
924
ent/note_update.go
Normal file
|
|
@ -0,0 +1,924 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/attachment"
|
||||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
// NoteUpdate is the builder for updating Note entities.
|
||||
type NoteUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *NoteMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NoteUpdate builder.
|
||||
func (nu *NoteUpdate) Where(ps ...predicate.Note) *NoteUpdate {
|
||||
nu.mutation.Where(ps...)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetIsRemote sets the "isRemote" field.
|
||||
func (nu *NoteUpdate) SetIsRemote(b bool) *NoteUpdate {
|
||||
nu.mutation.SetIsRemote(b)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetNillableIsRemote sets the "isRemote" field if the given value is not nil.
|
||||
func (nu *NoteUpdate) SetNillableIsRemote(b *bool) *NoteUpdate {
|
||||
if b != nil {
|
||||
nu.SetIsRemote(*b)
|
||||
}
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetURI sets the "uri" field.
|
||||
func (nu *NoteUpdate) SetURI(s string) *NoteUpdate {
|
||||
nu.mutation.SetURI(s)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetNillableURI sets the "uri" field if the given value is not nil.
|
||||
func (nu *NoteUpdate) SetNillableURI(s *string) *NoteUpdate {
|
||||
if s != nil {
|
||||
nu.SetURI(*s)
|
||||
}
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (nu *NoteUpdate) SetExtensions(l lysand.Extensions) *NoteUpdate {
|
||||
nu.mutation.SetExtensions(l)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (nu *NoteUpdate) SetUpdatedAt(t time.Time) *NoteUpdate {
|
||||
nu.mutation.SetUpdatedAt(t)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetSubject sets the "subject" field.
|
||||
func (nu *NoteUpdate) SetSubject(s string) *NoteUpdate {
|
||||
nu.mutation.SetSubject(s)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetNillableSubject sets the "subject" field if the given value is not nil.
|
||||
func (nu *NoteUpdate) SetNillableSubject(s *string) *NoteUpdate {
|
||||
if s != nil {
|
||||
nu.SetSubject(*s)
|
||||
}
|
||||
return nu
|
||||
}
|
||||
|
||||
// ClearSubject clears the value of the "subject" field.
|
||||
func (nu *NoteUpdate) ClearSubject() *NoteUpdate {
|
||||
nu.mutation.ClearSubject()
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (nu *NoteUpdate) SetContent(s string) *NoteUpdate {
|
||||
nu.mutation.SetContent(s)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetNillableContent sets the "content" field if the given value is not nil.
|
||||
func (nu *NoteUpdate) SetNillableContent(s *string) *NoteUpdate {
|
||||
if s != nil {
|
||||
nu.SetContent(*s)
|
||||
}
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetIsSensitive sets the "isSensitive" field.
|
||||
func (nu *NoteUpdate) SetIsSensitive(b bool) *NoteUpdate {
|
||||
nu.mutation.SetIsSensitive(b)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetNillableIsSensitive sets the "isSensitive" field if the given value is not nil.
|
||||
func (nu *NoteUpdate) SetNillableIsSensitive(b *bool) *NoteUpdate {
|
||||
if b != nil {
|
||||
nu.SetIsSensitive(*b)
|
||||
}
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetVisibility sets the "visibility" field.
|
||||
func (nu *NoteUpdate) SetVisibility(n note.Visibility) *NoteUpdate {
|
||||
nu.mutation.SetVisibility(n)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetNillableVisibility sets the "visibility" field if the given value is not nil.
|
||||
func (nu *NoteUpdate) SetNillableVisibility(n *note.Visibility) *NoteUpdate {
|
||||
if n != nil {
|
||||
nu.SetVisibility(*n)
|
||||
}
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetAuthorID sets the "author" edge to the User entity by ID.
|
||||
func (nu *NoteUpdate) SetAuthorID(id uuid.UUID) *NoteUpdate {
|
||||
nu.mutation.SetAuthorID(id)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetAuthor sets the "author" edge to the User entity.
|
||||
func (nu *NoteUpdate) SetAuthor(u *User) *NoteUpdate {
|
||||
return nu.SetAuthorID(u.ID)
|
||||
}
|
||||
|
||||
// AddMentionIDs adds the "mentions" edge to the User entity by IDs.
|
||||
func (nu *NoteUpdate) AddMentionIDs(ids ...uuid.UUID) *NoteUpdate {
|
||||
nu.mutation.AddMentionIDs(ids...)
|
||||
return nu
|
||||
}
|
||||
|
||||
// AddMentions adds the "mentions" edges to the User entity.
|
||||
func (nu *NoteUpdate) AddMentions(u ...*User) *NoteUpdate {
|
||||
ids := make([]uuid.UUID, len(u))
|
||||
for i := range u {
|
||||
ids[i] = u[i].ID
|
||||
}
|
||||
return nu.AddMentionIDs(ids...)
|
||||
}
|
||||
|
||||
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
||||
func (nu *NoteUpdate) AddAttachmentIDs(ids ...uuid.UUID) *NoteUpdate {
|
||||
nu.mutation.AddAttachmentIDs(ids...)
|
||||
return nu
|
||||
}
|
||||
|
||||
// AddAttachments adds the "attachments" edges to the Attachment entity.
|
||||
func (nu *NoteUpdate) AddAttachments(a ...*Attachment) *NoteUpdate {
|
||||
ids := make([]uuid.UUID, len(a))
|
||||
for i := range a {
|
||||
ids[i] = a[i].ID
|
||||
}
|
||||
return nu.AddAttachmentIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the NoteMutation object of the builder.
|
||||
func (nu *NoteUpdate) Mutation() *NoteMutation {
|
||||
return nu.mutation
|
||||
}
|
||||
|
||||
// ClearAuthor clears the "author" edge to the User entity.
|
||||
func (nu *NoteUpdate) ClearAuthor() *NoteUpdate {
|
||||
nu.mutation.ClearAuthor()
|
||||
return nu
|
||||
}
|
||||
|
||||
// ClearMentions clears all "mentions" edges to the User entity.
|
||||
func (nu *NoteUpdate) ClearMentions() *NoteUpdate {
|
||||
nu.mutation.ClearMentions()
|
||||
return nu
|
||||
}
|
||||
|
||||
// RemoveMentionIDs removes the "mentions" edge to User entities by IDs.
|
||||
func (nu *NoteUpdate) RemoveMentionIDs(ids ...uuid.UUID) *NoteUpdate {
|
||||
nu.mutation.RemoveMentionIDs(ids...)
|
||||
return nu
|
||||
}
|
||||
|
||||
// RemoveMentions removes "mentions" edges to User entities.
|
||||
func (nu *NoteUpdate) RemoveMentions(u ...*User) *NoteUpdate {
|
||||
ids := make([]uuid.UUID, len(u))
|
||||
for i := range u {
|
||||
ids[i] = u[i].ID
|
||||
}
|
||||
return nu.RemoveMentionIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
||||
func (nu *NoteUpdate) ClearAttachments() *NoteUpdate {
|
||||
nu.mutation.ClearAttachments()
|
||||
return nu
|
||||
}
|
||||
|
||||
// RemoveAttachmentIDs removes the "attachments" edge to Attachment entities by IDs.
|
||||
func (nu *NoteUpdate) RemoveAttachmentIDs(ids ...uuid.UUID) *NoteUpdate {
|
||||
nu.mutation.RemoveAttachmentIDs(ids...)
|
||||
return nu
|
||||
}
|
||||
|
||||
// RemoveAttachments removes "attachments" edges to Attachment entities.
|
||||
func (nu *NoteUpdate) RemoveAttachments(a ...*Attachment) *NoteUpdate {
|
||||
ids := make([]uuid.UUID, len(a))
|
||||
for i := range a {
|
||||
ids[i] = a[i].ID
|
||||
}
|
||||
return nu.RemoveAttachmentIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (nu *NoteUpdate) Save(ctx context.Context) (int, error) {
|
||||
nu.defaults()
|
||||
return withHooks(ctx, nu.sqlSave, nu.mutation, nu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (nu *NoteUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := nu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (nu *NoteUpdate) Exec(ctx context.Context) error {
|
||||
_, err := nu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (nu *NoteUpdate) ExecX(ctx context.Context) {
|
||||
if err := nu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (nu *NoteUpdate) defaults() {
|
||||
if _, ok := nu.mutation.UpdatedAt(); !ok {
|
||||
v := note.UpdateDefaultUpdatedAt()
|
||||
nu.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (nu *NoteUpdate) check() error {
|
||||
if v, ok := nu.mutation.URI(); ok {
|
||||
if err := note.URIValidator(v); err != nil {
|
||||
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "Note.uri": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := nu.mutation.Subject(); ok {
|
||||
if err := note.SubjectValidator(v); err != nil {
|
||||
return &ValidationError{Name: "subject", err: fmt.Errorf(`ent: validator failed for field "Note.subject": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := nu.mutation.Visibility(); ok {
|
||||
if err := note.VisibilityValidator(v); err != nil {
|
||||
return &ValidationError{Name: "visibility", err: fmt.Errorf(`ent: validator failed for field "Note.visibility": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := nu.mutation.AuthorID(); nu.mutation.AuthorCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Note.author"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nu *NoteUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := nu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(note.Table, note.Columns, sqlgraph.NewFieldSpec(note.FieldID, field.TypeUUID))
|
||||
if ps := nu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := nu.mutation.IsRemote(); ok {
|
||||
_spec.SetField(note.FieldIsRemote, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := nu.mutation.URI(); ok {
|
||||
_spec.SetField(note.FieldURI, field.TypeString, value)
|
||||
}
|
||||
if value, ok := nu.mutation.Extensions(); ok {
|
||||
_spec.SetField(note.FieldExtensions, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := nu.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(note.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := nu.mutation.Subject(); ok {
|
||||
_spec.SetField(note.FieldSubject, field.TypeString, value)
|
||||
}
|
||||
if nu.mutation.SubjectCleared() {
|
||||
_spec.ClearField(note.FieldSubject, field.TypeString)
|
||||
}
|
||||
if value, ok := nu.mutation.Content(); ok {
|
||||
_spec.SetField(note.FieldContent, field.TypeString, value)
|
||||
}
|
||||
if value, ok := nu.mutation.IsSensitive(); ok {
|
||||
_spec.SetField(note.FieldIsSensitive, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := nu.mutation.Visibility(); ok {
|
||||
_spec.SetField(note.FieldVisibility, field.TypeEnum, value)
|
||||
}
|
||||
if nu.mutation.AuthorCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: note.AuthorTable,
|
||||
Columns: []string{note.AuthorColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nu.mutation.AuthorIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: note.AuthorTable,
|
||||
Columns: []string{note.AuthorColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if nu.mutation.MentionsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: note.MentionsTable,
|
||||
Columns: note.MentionsPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nu.mutation.RemovedMentionsIDs(); len(nodes) > 0 && !nu.mutation.MentionsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: note.MentionsTable,
|
||||
Columns: note.MentionsPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nu.mutation.MentionsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: note.MentionsTable,
|
||||
Columns: note.MentionsPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if nu.mutation.AttachmentsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: note.AttachmentsTable,
|
||||
Columns: []string{note.AttachmentsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nu.mutation.RemovedAttachmentsIDs(); len(nodes) > 0 && !nu.mutation.AttachmentsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: note.AttachmentsTable,
|
||||
Columns: []string{note.AttachmentsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nu.mutation.AttachmentsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: note.AttachmentsTable,
|
||||
Columns: []string{note.AttachmentsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, nu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{note.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
nu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// NoteUpdateOne is the builder for updating a single Note entity.
|
||||
type NoteUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *NoteMutation
|
||||
}
|
||||
|
||||
// SetIsRemote sets the "isRemote" field.
|
||||
func (nuo *NoteUpdateOne) SetIsRemote(b bool) *NoteUpdateOne {
|
||||
nuo.mutation.SetIsRemote(b)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetNillableIsRemote sets the "isRemote" field if the given value is not nil.
|
||||
func (nuo *NoteUpdateOne) SetNillableIsRemote(b *bool) *NoteUpdateOne {
|
||||
if b != nil {
|
||||
nuo.SetIsRemote(*b)
|
||||
}
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetURI sets the "uri" field.
|
||||
func (nuo *NoteUpdateOne) SetURI(s string) *NoteUpdateOne {
|
||||
nuo.mutation.SetURI(s)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetNillableURI sets the "uri" field if the given value is not nil.
|
||||
func (nuo *NoteUpdateOne) SetNillableURI(s *string) *NoteUpdateOne {
|
||||
if s != nil {
|
||||
nuo.SetURI(*s)
|
||||
}
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (nuo *NoteUpdateOne) SetExtensions(l lysand.Extensions) *NoteUpdateOne {
|
||||
nuo.mutation.SetExtensions(l)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (nuo *NoteUpdateOne) SetUpdatedAt(t time.Time) *NoteUpdateOne {
|
||||
nuo.mutation.SetUpdatedAt(t)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetSubject sets the "subject" field.
|
||||
func (nuo *NoteUpdateOne) SetSubject(s string) *NoteUpdateOne {
|
||||
nuo.mutation.SetSubject(s)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetNillableSubject sets the "subject" field if the given value is not nil.
|
||||
func (nuo *NoteUpdateOne) SetNillableSubject(s *string) *NoteUpdateOne {
|
||||
if s != nil {
|
||||
nuo.SetSubject(*s)
|
||||
}
|
||||
return nuo
|
||||
}
|
||||
|
||||
// ClearSubject clears the value of the "subject" field.
|
||||
func (nuo *NoteUpdateOne) ClearSubject() *NoteUpdateOne {
|
||||
nuo.mutation.ClearSubject()
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (nuo *NoteUpdateOne) SetContent(s string) *NoteUpdateOne {
|
||||
nuo.mutation.SetContent(s)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetNillableContent sets the "content" field if the given value is not nil.
|
||||
func (nuo *NoteUpdateOne) SetNillableContent(s *string) *NoteUpdateOne {
|
||||
if s != nil {
|
||||
nuo.SetContent(*s)
|
||||
}
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetIsSensitive sets the "isSensitive" field.
|
||||
func (nuo *NoteUpdateOne) SetIsSensitive(b bool) *NoteUpdateOne {
|
||||
nuo.mutation.SetIsSensitive(b)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetNillableIsSensitive sets the "isSensitive" field if the given value is not nil.
|
||||
func (nuo *NoteUpdateOne) SetNillableIsSensitive(b *bool) *NoteUpdateOne {
|
||||
if b != nil {
|
||||
nuo.SetIsSensitive(*b)
|
||||
}
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetVisibility sets the "visibility" field.
|
||||
func (nuo *NoteUpdateOne) SetVisibility(n note.Visibility) *NoteUpdateOne {
|
||||
nuo.mutation.SetVisibility(n)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetNillableVisibility sets the "visibility" field if the given value is not nil.
|
||||
func (nuo *NoteUpdateOne) SetNillableVisibility(n *note.Visibility) *NoteUpdateOne {
|
||||
if n != nil {
|
||||
nuo.SetVisibility(*n)
|
||||
}
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetAuthorID sets the "author" edge to the User entity by ID.
|
||||
func (nuo *NoteUpdateOne) SetAuthorID(id uuid.UUID) *NoteUpdateOne {
|
||||
nuo.mutation.SetAuthorID(id)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetAuthor sets the "author" edge to the User entity.
|
||||
func (nuo *NoteUpdateOne) SetAuthor(u *User) *NoteUpdateOne {
|
||||
return nuo.SetAuthorID(u.ID)
|
||||
}
|
||||
|
||||
// AddMentionIDs adds the "mentions" edge to the User entity by IDs.
|
||||
func (nuo *NoteUpdateOne) AddMentionIDs(ids ...uuid.UUID) *NoteUpdateOne {
|
||||
nuo.mutation.AddMentionIDs(ids...)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// AddMentions adds the "mentions" edges to the User entity.
|
||||
func (nuo *NoteUpdateOne) AddMentions(u ...*User) *NoteUpdateOne {
|
||||
ids := make([]uuid.UUID, len(u))
|
||||
for i := range u {
|
||||
ids[i] = u[i].ID
|
||||
}
|
||||
return nuo.AddMentionIDs(ids...)
|
||||
}
|
||||
|
||||
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
||||
func (nuo *NoteUpdateOne) AddAttachmentIDs(ids ...uuid.UUID) *NoteUpdateOne {
|
||||
nuo.mutation.AddAttachmentIDs(ids...)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// AddAttachments adds the "attachments" edges to the Attachment entity.
|
||||
func (nuo *NoteUpdateOne) AddAttachments(a ...*Attachment) *NoteUpdateOne {
|
||||
ids := make([]uuid.UUID, len(a))
|
||||
for i := range a {
|
||||
ids[i] = a[i].ID
|
||||
}
|
||||
return nuo.AddAttachmentIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the NoteMutation object of the builder.
|
||||
func (nuo *NoteUpdateOne) Mutation() *NoteMutation {
|
||||
return nuo.mutation
|
||||
}
|
||||
|
||||
// ClearAuthor clears the "author" edge to the User entity.
|
||||
func (nuo *NoteUpdateOne) ClearAuthor() *NoteUpdateOne {
|
||||
nuo.mutation.ClearAuthor()
|
||||
return nuo
|
||||
}
|
||||
|
||||
// ClearMentions clears all "mentions" edges to the User entity.
|
||||
func (nuo *NoteUpdateOne) ClearMentions() *NoteUpdateOne {
|
||||
nuo.mutation.ClearMentions()
|
||||
return nuo
|
||||
}
|
||||
|
||||
// RemoveMentionIDs removes the "mentions" edge to User entities by IDs.
|
||||
func (nuo *NoteUpdateOne) RemoveMentionIDs(ids ...uuid.UUID) *NoteUpdateOne {
|
||||
nuo.mutation.RemoveMentionIDs(ids...)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// RemoveMentions removes "mentions" edges to User entities.
|
||||
func (nuo *NoteUpdateOne) RemoveMentions(u ...*User) *NoteUpdateOne {
|
||||
ids := make([]uuid.UUID, len(u))
|
||||
for i := range u {
|
||||
ids[i] = u[i].ID
|
||||
}
|
||||
return nuo.RemoveMentionIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
||||
func (nuo *NoteUpdateOne) ClearAttachments() *NoteUpdateOne {
|
||||
nuo.mutation.ClearAttachments()
|
||||
return nuo
|
||||
}
|
||||
|
||||
// RemoveAttachmentIDs removes the "attachments" edge to Attachment entities by IDs.
|
||||
func (nuo *NoteUpdateOne) RemoveAttachmentIDs(ids ...uuid.UUID) *NoteUpdateOne {
|
||||
nuo.mutation.RemoveAttachmentIDs(ids...)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// RemoveAttachments removes "attachments" edges to Attachment entities.
|
||||
func (nuo *NoteUpdateOne) RemoveAttachments(a ...*Attachment) *NoteUpdateOne {
|
||||
ids := make([]uuid.UUID, len(a))
|
||||
for i := range a {
|
||||
ids[i] = a[i].ID
|
||||
}
|
||||
return nuo.RemoveAttachmentIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NoteUpdate builder.
|
||||
func (nuo *NoteUpdateOne) Where(ps ...predicate.Note) *NoteUpdateOne {
|
||||
nuo.mutation.Where(ps...)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (nuo *NoteUpdateOne) Select(field string, fields ...string) *NoteUpdateOne {
|
||||
nuo.fields = append([]string{field}, fields...)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Note entity.
|
||||
func (nuo *NoteUpdateOne) Save(ctx context.Context) (*Note, error) {
|
||||
nuo.defaults()
|
||||
return withHooks(ctx, nuo.sqlSave, nuo.mutation, nuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (nuo *NoteUpdateOne) SaveX(ctx context.Context) *Note {
|
||||
node, err := nuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (nuo *NoteUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := nuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (nuo *NoteUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := nuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (nuo *NoteUpdateOne) defaults() {
|
||||
if _, ok := nuo.mutation.UpdatedAt(); !ok {
|
||||
v := note.UpdateDefaultUpdatedAt()
|
||||
nuo.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (nuo *NoteUpdateOne) check() error {
|
||||
if v, ok := nuo.mutation.URI(); ok {
|
||||
if err := note.URIValidator(v); err != nil {
|
||||
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "Note.uri": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := nuo.mutation.Subject(); ok {
|
||||
if err := note.SubjectValidator(v); err != nil {
|
||||
return &ValidationError{Name: "subject", err: fmt.Errorf(`ent: validator failed for field "Note.subject": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := nuo.mutation.Visibility(); ok {
|
||||
if err := note.VisibilityValidator(v); err != nil {
|
||||
return &ValidationError{Name: "visibility", err: fmt.Errorf(`ent: validator failed for field "Note.visibility": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := nuo.mutation.AuthorID(); nuo.mutation.AuthorCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Note.author"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nuo *NoteUpdateOne) sqlSave(ctx context.Context) (_node *Note, err error) {
|
||||
if err := nuo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(note.Table, note.Columns, sqlgraph.NewFieldSpec(note.FieldID, field.TypeUUID))
|
||||
id, ok := nuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Note.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := nuo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, note.FieldID)
|
||||
for _, f := range fields {
|
||||
if !note.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != note.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := nuo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := nuo.mutation.IsRemote(); ok {
|
||||
_spec.SetField(note.FieldIsRemote, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := nuo.mutation.URI(); ok {
|
||||
_spec.SetField(note.FieldURI, field.TypeString, value)
|
||||
}
|
||||
if value, ok := nuo.mutation.Extensions(); ok {
|
||||
_spec.SetField(note.FieldExtensions, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := nuo.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(note.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := nuo.mutation.Subject(); ok {
|
||||
_spec.SetField(note.FieldSubject, field.TypeString, value)
|
||||
}
|
||||
if nuo.mutation.SubjectCleared() {
|
||||
_spec.ClearField(note.FieldSubject, field.TypeString)
|
||||
}
|
||||
if value, ok := nuo.mutation.Content(); ok {
|
||||
_spec.SetField(note.FieldContent, field.TypeString, value)
|
||||
}
|
||||
if value, ok := nuo.mutation.IsSensitive(); ok {
|
||||
_spec.SetField(note.FieldIsSensitive, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := nuo.mutation.Visibility(); ok {
|
||||
_spec.SetField(note.FieldVisibility, field.TypeEnum, value)
|
||||
}
|
||||
if nuo.mutation.AuthorCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: note.AuthorTable,
|
||||
Columns: []string{note.AuthorColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nuo.mutation.AuthorIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: note.AuthorTable,
|
||||
Columns: []string{note.AuthorColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if nuo.mutation.MentionsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: note.MentionsTable,
|
||||
Columns: note.MentionsPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nuo.mutation.RemovedMentionsIDs(); len(nodes) > 0 && !nuo.mutation.MentionsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: note.MentionsTable,
|
||||
Columns: note.MentionsPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nuo.mutation.MentionsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: note.MentionsTable,
|
||||
Columns: note.MentionsPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if nuo.mutation.AttachmentsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: note.AttachmentsTable,
|
||||
Columns: []string{note.AttachmentsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nuo.mutation.RemovedAttachmentsIDs(); len(nodes) > 0 && !nuo.mutation.AttachmentsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: note.AttachmentsTable,
|
||||
Columns: []string{note.AttachmentsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nuo.mutation.AttachmentsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: note.AttachmentsTable,
|
||||
Columns: []string{note.AttachmentsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Note{config: nuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, nuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{note.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
nuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
25
ent/predicate/predicate.go
Normal file
25
ent/predicate/predicate.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package predicate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Attachment is the predicate function for attachment builders.
|
||||
type Attachment func(*sql.Selector)
|
||||
|
||||
// Follow is the predicate function for follow builders.
|
||||
type Follow func(*sql.Selector)
|
||||
|
||||
// Image is the predicate function for image builders.
|
||||
type Image func(*sql.Selector)
|
||||
|
||||
// Note is the predicate function for note builders.
|
||||
type Note func(*sql.Selector)
|
||||
|
||||
// ServerMetadata is the predicate function for servermetadata builders.
|
||||
type ServerMetadata func(*sql.Selector)
|
||||
|
||||
// User is the predicate function for user builders.
|
||||
type User func(*sql.Selector)
|
||||
231
ent/runtime.go
Normal file
231
ent/runtime.go
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/attachment"
|
||||
"github.com/lysand-org/versia-go/ent/follow"
|
||||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/schema"
|
||||
"github.com/lysand-org/versia-go/ent/servermetadata"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
// The init function reads all schema descriptors with runtime code
|
||||
// (default values, validators, hooks and policies) and stitches it
|
||||
// to their package variables.
|
||||
func init() {
|
||||
attachmentMixin := schema.Attachment{}.Mixin()
|
||||
attachmentMixinFields0 := attachmentMixin[0].Fields()
|
||||
_ = attachmentMixinFields0
|
||||
attachmentFields := schema.Attachment{}.Fields()
|
||||
_ = attachmentFields
|
||||
// attachmentDescURI is the schema descriptor for uri field.
|
||||
attachmentDescURI := attachmentMixinFields0[2].Descriptor()
|
||||
// attachment.URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
attachment.URIValidator = attachmentDescURI.Validators[0].(func(string) error)
|
||||
// attachmentDescExtensions is the schema descriptor for extensions field.
|
||||
attachmentDescExtensions := attachmentMixinFields0[3].Descriptor()
|
||||
// attachment.DefaultExtensions holds the default value on creation for the extensions field.
|
||||
attachment.DefaultExtensions = attachmentDescExtensions.Default.(lysand.Extensions)
|
||||
// attachmentDescCreatedAt is the schema descriptor for created_at field.
|
||||
attachmentDescCreatedAt := attachmentMixinFields0[4].Descriptor()
|
||||
// attachment.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
attachment.DefaultCreatedAt = attachmentDescCreatedAt.Default.(func() time.Time)
|
||||
// attachmentDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
attachmentDescUpdatedAt := attachmentMixinFields0[5].Descriptor()
|
||||
// attachment.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
attachment.DefaultUpdatedAt = attachmentDescUpdatedAt.Default.(func() time.Time)
|
||||
// attachment.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
attachment.UpdateDefaultUpdatedAt = attachmentDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
// attachmentDescDescription is the schema descriptor for description field.
|
||||
attachmentDescDescription := attachmentFields[0].Descriptor()
|
||||
// attachment.DescriptionValidator is a validator for the "description" field. It is called by the builders before save.
|
||||
attachment.DescriptionValidator = attachmentDescDescription.Validators[0].(func(string) error)
|
||||
// attachmentDescID is the schema descriptor for id field.
|
||||
attachmentDescID := attachmentMixinFields0[0].Descriptor()
|
||||
// attachment.DefaultID holds the default value on creation for the id field.
|
||||
attachment.DefaultID = attachmentDescID.Default.(func() uuid.UUID)
|
||||
followMixin := schema.Follow{}.Mixin()
|
||||
followMixinFields0 := followMixin[0].Fields()
|
||||
_ = followMixinFields0
|
||||
followFields := schema.Follow{}.Fields()
|
||||
_ = followFields
|
||||
// followDescURI is the schema descriptor for uri field.
|
||||
followDescURI := followMixinFields0[2].Descriptor()
|
||||
// follow.URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
follow.URIValidator = followDescURI.Validators[0].(func(string) error)
|
||||
// followDescExtensions is the schema descriptor for extensions field.
|
||||
followDescExtensions := followMixinFields0[3].Descriptor()
|
||||
// follow.DefaultExtensions holds the default value on creation for the extensions field.
|
||||
follow.DefaultExtensions = followDescExtensions.Default.(lysand.Extensions)
|
||||
// followDescCreatedAt is the schema descriptor for created_at field.
|
||||
followDescCreatedAt := followMixinFields0[4].Descriptor()
|
||||
// follow.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
follow.DefaultCreatedAt = followDescCreatedAt.Default.(func() time.Time)
|
||||
// followDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
followDescUpdatedAt := followMixinFields0[5].Descriptor()
|
||||
// follow.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
follow.DefaultUpdatedAt = followDescUpdatedAt.Default.(func() time.Time)
|
||||
// follow.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
follow.UpdateDefaultUpdatedAt = followDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
// followDescID is the schema descriptor for id field.
|
||||
followDescID := followMixinFields0[0].Descriptor()
|
||||
// follow.DefaultID holds the default value on creation for the id field.
|
||||
follow.DefaultID = followDescID.Default.(func() uuid.UUID)
|
||||
noteMixin := schema.Note{}.Mixin()
|
||||
noteMixinFields0 := noteMixin[0].Fields()
|
||||
_ = noteMixinFields0
|
||||
noteFields := schema.Note{}.Fields()
|
||||
_ = noteFields
|
||||
// noteDescURI is the schema descriptor for uri field.
|
||||
noteDescURI := noteMixinFields0[2].Descriptor()
|
||||
// note.URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
note.URIValidator = noteDescURI.Validators[0].(func(string) error)
|
||||
// noteDescExtensions is the schema descriptor for extensions field.
|
||||
noteDescExtensions := noteMixinFields0[3].Descriptor()
|
||||
// note.DefaultExtensions holds the default value on creation for the extensions field.
|
||||
note.DefaultExtensions = noteDescExtensions.Default.(lysand.Extensions)
|
||||
// noteDescCreatedAt is the schema descriptor for created_at field.
|
||||
noteDescCreatedAt := noteMixinFields0[4].Descriptor()
|
||||
// note.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
note.DefaultCreatedAt = noteDescCreatedAt.Default.(func() time.Time)
|
||||
// noteDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
noteDescUpdatedAt := noteMixinFields0[5].Descriptor()
|
||||
// note.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
note.DefaultUpdatedAt = noteDescUpdatedAt.Default.(func() time.Time)
|
||||
// note.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
note.UpdateDefaultUpdatedAt = noteDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
// noteDescSubject is the schema descriptor for subject field.
|
||||
noteDescSubject := noteFields[0].Descriptor()
|
||||
// note.SubjectValidator is a validator for the "subject" field. It is called by the builders before save.
|
||||
note.SubjectValidator = noteDescSubject.Validators[0].(func(string) error)
|
||||
// noteDescIsSensitive is the schema descriptor for isSensitive field.
|
||||
noteDescIsSensitive := noteFields[2].Descriptor()
|
||||
// note.DefaultIsSensitive holds the default value on creation for the isSensitive field.
|
||||
note.DefaultIsSensitive = noteDescIsSensitive.Default.(bool)
|
||||
// noteDescID is the schema descriptor for id field.
|
||||
noteDescID := noteMixinFields0[0].Descriptor()
|
||||
// note.DefaultID holds the default value on creation for the id field.
|
||||
note.DefaultID = noteDescID.Default.(func() uuid.UUID)
|
||||
servermetadataMixin := schema.ServerMetadata{}.Mixin()
|
||||
servermetadataMixinFields0 := servermetadataMixin[0].Fields()
|
||||
_ = servermetadataMixinFields0
|
||||
servermetadataFields := schema.ServerMetadata{}.Fields()
|
||||
_ = servermetadataFields
|
||||
// servermetadataDescURI is the schema descriptor for uri field.
|
||||
servermetadataDescURI := servermetadataMixinFields0[2].Descriptor()
|
||||
// servermetadata.URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
servermetadata.URIValidator = servermetadataDescURI.Validators[0].(func(string) error)
|
||||
// servermetadataDescExtensions is the schema descriptor for extensions field.
|
||||
servermetadataDescExtensions := servermetadataMixinFields0[3].Descriptor()
|
||||
// servermetadata.DefaultExtensions holds the default value on creation for the extensions field.
|
||||
servermetadata.DefaultExtensions = servermetadataDescExtensions.Default.(lysand.Extensions)
|
||||
// servermetadataDescCreatedAt is the schema descriptor for created_at field.
|
||||
servermetadataDescCreatedAt := servermetadataMixinFields0[4].Descriptor()
|
||||
// servermetadata.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
servermetadata.DefaultCreatedAt = servermetadataDescCreatedAt.Default.(func() time.Time)
|
||||
// servermetadataDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
servermetadataDescUpdatedAt := servermetadataMixinFields0[5].Descriptor()
|
||||
// servermetadata.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
servermetadata.DefaultUpdatedAt = servermetadataDescUpdatedAt.Default.(func() time.Time)
|
||||
// servermetadata.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
servermetadata.UpdateDefaultUpdatedAt = servermetadataDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
// servermetadataDescName is the schema descriptor for name field.
|
||||
servermetadataDescName := servermetadataFields[0].Descriptor()
|
||||
// servermetadata.NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||
servermetadata.NameValidator = servermetadataDescName.Validators[0].(func(string) error)
|
||||
// servermetadataDescVersion is the schema descriptor for version field.
|
||||
servermetadataDescVersion := servermetadataFields[2].Descriptor()
|
||||
// servermetadata.VersionValidator is a validator for the "version" field. It is called by the builders before save.
|
||||
servermetadata.VersionValidator = servermetadataDescVersion.Validators[0].(func(string) error)
|
||||
// servermetadataDescSupportedExtensions is the schema descriptor for supportedExtensions field.
|
||||
servermetadataDescSupportedExtensions := servermetadataFields[3].Descriptor()
|
||||
// servermetadata.DefaultSupportedExtensions holds the default value on creation for the supportedExtensions field.
|
||||
servermetadata.DefaultSupportedExtensions = servermetadataDescSupportedExtensions.Default.([]string)
|
||||
// servermetadataDescID is the schema descriptor for id field.
|
||||
servermetadataDescID := servermetadataMixinFields0[0].Descriptor()
|
||||
// servermetadata.DefaultID holds the default value on creation for the id field.
|
||||
servermetadata.DefaultID = servermetadataDescID.Default.(func() uuid.UUID)
|
||||
userMixin := schema.User{}.Mixin()
|
||||
userMixinFields0 := userMixin[0].Fields()
|
||||
_ = userMixinFields0
|
||||
userFields := schema.User{}.Fields()
|
||||
_ = userFields
|
||||
// userDescURI is the schema descriptor for uri field.
|
||||
userDescURI := userMixinFields0[2].Descriptor()
|
||||
// user.URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
user.URIValidator = userDescURI.Validators[0].(func(string) error)
|
||||
// userDescExtensions is the schema descriptor for extensions field.
|
||||
userDescExtensions := userMixinFields0[3].Descriptor()
|
||||
// user.DefaultExtensions holds the default value on creation for the extensions field.
|
||||
user.DefaultExtensions = userDescExtensions.Default.(lysand.Extensions)
|
||||
// userDescCreatedAt is the schema descriptor for created_at field.
|
||||
userDescCreatedAt := userMixinFields0[4].Descriptor()
|
||||
// user.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time)
|
||||
// userDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
userDescUpdatedAt := userMixinFields0[5].Descriptor()
|
||||
// user.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
user.DefaultUpdatedAt = userDescUpdatedAt.Default.(func() time.Time)
|
||||
// user.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
user.UpdateDefaultUpdatedAt = userDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
// userDescUsername is the schema descriptor for username field.
|
||||
userDescUsername := userFields[0].Descriptor()
|
||||
// user.UsernameValidator is a validator for the "username" field. It is called by the builders before save.
|
||||
user.UsernameValidator = func() func(string) error {
|
||||
validators := userDescUsername.Validators
|
||||
fns := [...]func(string) error{
|
||||
validators[0].(func(string) error),
|
||||
validators[1].(func(string) error),
|
||||
}
|
||||
return func(username string) error {
|
||||
for _, fn := range fns {
|
||||
if err := fn(username); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}()
|
||||
// userDescDisplayName is the schema descriptor for displayName field.
|
||||
userDescDisplayName := userFields[2].Descriptor()
|
||||
// user.DisplayNameValidator is a validator for the "displayName" field. It is called by the builders before save.
|
||||
user.DisplayNameValidator = userDescDisplayName.Validators[0].(func(string) error)
|
||||
// userDescIndexable is the schema descriptor for indexable field.
|
||||
userDescIndexable := userFields[6].Descriptor()
|
||||
// user.DefaultIndexable holds the default value on creation for the indexable field.
|
||||
user.DefaultIndexable = userDescIndexable.Default.(bool)
|
||||
// userDescFields is the schema descriptor for fields field.
|
||||
userDescFields := userFields[8].Descriptor()
|
||||
// user.DefaultFields holds the default value on creation for the fields field.
|
||||
user.DefaultFields = userDescFields.Default.([]lysand.Field)
|
||||
// userDescInbox is the schema descriptor for inbox field.
|
||||
userDescInbox := userFields[9].Descriptor()
|
||||
// user.InboxValidator is a validator for the "inbox" field. It is called by the builders before save.
|
||||
user.InboxValidator = userDescInbox.Validators[0].(func(string) error)
|
||||
// userDescFeatured is the schema descriptor for featured field.
|
||||
userDescFeatured := userFields[10].Descriptor()
|
||||
// user.FeaturedValidator is a validator for the "featured" field. It is called by the builders before save.
|
||||
user.FeaturedValidator = userDescFeatured.Validators[0].(func(string) error)
|
||||
// userDescFollowers is the schema descriptor for followers field.
|
||||
userDescFollowers := userFields[11].Descriptor()
|
||||
// user.FollowersValidator is a validator for the "followers" field. It is called by the builders before save.
|
||||
user.FollowersValidator = userDescFollowers.Validators[0].(func(string) error)
|
||||
// userDescFollowing is the schema descriptor for following field.
|
||||
userDescFollowing := userFields[12].Descriptor()
|
||||
// user.FollowingValidator is a validator for the "following" field. It is called by the builders before save.
|
||||
user.FollowingValidator = userDescFollowing.Validators[0].(func(string) error)
|
||||
// userDescOutbox is the schema descriptor for outbox field.
|
||||
userDescOutbox := userFields[13].Descriptor()
|
||||
// user.OutboxValidator is a validator for the "outbox" field. It is called by the builders before save.
|
||||
user.OutboxValidator = userDescOutbox.Validators[0].(func(string) error)
|
||||
// userDescID is the schema descriptor for id field.
|
||||
userDescID := userMixinFields0[0].Descriptor()
|
||||
// user.DefaultID holds the default value on creation for the id field.
|
||||
user.DefaultID = userDescID.Default.(func() uuid.UUID)
|
||||
}
|
||||
10
ent/runtime/runtime.go
Normal file
10
ent/runtime/runtime.go
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package runtime
|
||||
|
||||
// The schema-stitching logic is generated in github.com/lysand-org/versia-go/ent/runtime.go
|
||||
|
||||
const (
|
||||
Version = "v0.13.1" // Version of ent codegen.
|
||||
Sum = "h1:uD8QwN1h6SNphdCCzmkMN3feSUzNnVvV/WIkHKMbzOE=" // Sum of ent codegen.
|
||||
)
|
||||
34
ent/schema/attachment.go
Normal file
34
ent/schema/attachment.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
type Attachment struct{ ent.Schema }
|
||||
|
||||
func (Attachment) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("description").MaxLen(384),
|
||||
field.Bytes("sha256"),
|
||||
field.Int("size"),
|
||||
|
||||
field.String("blurhash").Optional().Nillable(),
|
||||
field.Int("height").Optional().Nillable(),
|
||||
field.Int("width").Optional().Nillable(),
|
||||
field.Int("fps").Optional().Nillable(),
|
||||
|
||||
field.String("mimeType"),
|
||||
}
|
||||
}
|
||||
|
||||
func (Attachment) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("author", User.Type).Unique().Required(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Attachment) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{LysandEntityMixin{}}
|
||||
}
|
||||
33
ent/schema/follow.go
Normal file
33
ent/schema/follow.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
type Follow struct{ ent.Schema }
|
||||
|
||||
func (Follow) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Enum("status").Values("pending", "accepted").Default("pending"),
|
||||
}
|
||||
}
|
||||
|
||||
func (Follow) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("follower", User.Type).Unique().Required(),
|
||||
edge.To("followee", User.Type).Unique().Required(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Follow) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Edges("follower", "followee").Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Follow) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{LysandEntityMixin{}}
|
||||
}
|
||||
19
ent/schema/image.go
Normal file
19
ent/schema/image.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
type Image struct{ ent.Schema }
|
||||
|
||||
func (Image) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("url"),
|
||||
field.String("mimeType"),
|
||||
}
|
||||
}
|
||||
|
||||
func (Image) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
40
ent/schema/lysand_entity.go
Normal file
40
ent/schema/lysand_entity.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
type LysandEntityMixin struct{ mixin.Schema }
|
||||
|
||||
var _ ent.Mixin = (*LysandEntityMixin)(nil)
|
||||
|
||||
func (LysandEntityMixin) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.UUID{}).
|
||||
Default(uuid.New).
|
||||
Immutable(),
|
||||
field.Bool("isRemote"),
|
||||
field.String("uri").Validate(ValidateURI),
|
||||
|
||||
field.JSON("extensions", lysand.Extensions{}).Default(lysand.Extensions{}),
|
||||
|
||||
field.Time("created_at").
|
||||
Immutable().
|
||||
Default(time.Now),
|
||||
field.Time("updated_at").
|
||||
Default(time.Now).
|
||||
UpdateDefault(time.Now),
|
||||
}
|
||||
}
|
||||
|
||||
func ValidateURI(s string) error {
|
||||
_, err := url.Parse(s)
|
||||
return err
|
||||
}
|
||||
32
ent/schema/note.go
Normal file
32
ent/schema/note.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
type Note struct{ ent.Schema }
|
||||
|
||||
func (Note) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("subject").MaxLen(384).Optional().Nillable(),
|
||||
field.String("content"),
|
||||
|
||||
field.Bool("isSensitive").Default(false),
|
||||
field.Enum("visibility").Values("public", "unlisted", "followers", "direct").Default("public"),
|
||||
}
|
||||
}
|
||||
|
||||
func (Note) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("author", User.Type).Unique().Required(),
|
||||
edge.To("mentions", User.Type),
|
||||
|
||||
edge.To("attachments", Attachment.Type),
|
||||
}
|
||||
}
|
||||
|
||||
func (Note) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{LysandEntityMixin{}}
|
||||
}
|
||||
43
ent/schema/server_metadata.go
Normal file
43
ent/schema/server_metadata.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
type ServerMetadata struct{ ent.Schema }
|
||||
|
||||
func (ServerMetadata) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").
|
||||
NotEmpty(),
|
||||
field.String("description").
|
||||
Optional().
|
||||
Nillable(),
|
||||
|
||||
field.String("version").
|
||||
NotEmpty(),
|
||||
|
||||
field.Strings("supportedExtensions").
|
||||
Default([]string{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (ServerMetadata) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("follower", User.Type).Unique().Required(),
|
||||
edge.To("followee", User.Type).Unique().Required(),
|
||||
}
|
||||
}
|
||||
|
||||
func (ServerMetadata) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Edges("follower", "followee").Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (ServerMetadata) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{LysandEntityMixin{}}
|
||||
}
|
||||
65
ent/schema/user.go
Normal file
65
ent/schema/user.go
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"errors"
|
||||
"regexp"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUsernameInvalid = errors.New("username must match ^[a-z0-9_-]+$")
|
||||
usernameRegex = regexp.MustCompile("^[a-z0-9_-]+$")
|
||||
)
|
||||
|
||||
type User struct{ ent.Schema }
|
||||
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("username").Unique().MaxLen(32).Validate(ValidateUsername),
|
||||
field.Bytes("passwordHash").Optional().Nillable(),
|
||||
|
||||
field.String("displayName").MaxLen(256).Optional().Nillable(),
|
||||
field.String("biography").Optional().Nillable(),
|
||||
|
||||
field.Bytes("publicKey").GoType(ed25519.PublicKey([]byte{})),
|
||||
field.Bytes("privateKey").GoType(ed25519.PrivateKey([]byte{})).Optional(),
|
||||
|
||||
field.Bool("indexable").Default(true),
|
||||
field.Enum("privacyLevel").Values("public", "restricted", "private").Default("public"),
|
||||
|
||||
field.JSON("fields", []lysand.Field{}).Default([]lysand.Field{}),
|
||||
|
||||
field.String("inbox").Validate(ValidateURI),
|
||||
|
||||
// Collections
|
||||
field.String("featured").Validate(ValidateURI),
|
||||
field.String("followers").Validate(ValidateURI),
|
||||
field.String("following").Validate(ValidateURI),
|
||||
field.String("outbox").Validate(ValidateURI),
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("avatarImage", Image.Type).Unique(),
|
||||
edge.To("headerImage", Image.Type).Unique(),
|
||||
|
||||
edge.From("authoredNotes", Note.Type).Ref("author"),
|
||||
edge.From("mentionedNotes", Note.Type).Ref("mentions"),
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Mixin() []ent.Mixin { return []ent.Mixin{LysandEntityMixin{}} }
|
||||
|
||||
func ValidateUsername(username string) error {
|
||||
if !usernameRegex.MatchString(username) {
|
||||
return ErrUsernameInvalid
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
275
ent/servermetadata.go
Normal file
275
ent/servermetadata.go
Normal file
|
|
@ -0,0 +1,275 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/servermetadata"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
// ServerMetadata is the model entity for the ServerMetadata schema.
|
||||
type ServerMetadata struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID uuid.UUID `json:"id,omitempty"`
|
||||
// IsRemote holds the value of the "isRemote" field.
|
||||
IsRemote bool `json:"isRemote,omitempty"`
|
||||
// URI holds the value of the "uri" field.
|
||||
URI string `json:"uri,omitempty"`
|
||||
// Extensions holds the value of the "extensions" field.
|
||||
Extensions lysand.Extensions `json:"extensions,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Description holds the value of the "description" field.
|
||||
Description *string `json:"description,omitempty"`
|
||||
// Version holds the value of the "version" field.
|
||||
Version string `json:"version,omitempty"`
|
||||
// SupportedExtensions holds the value of the "supportedExtensions" field.
|
||||
SupportedExtensions []string `json:"supportedExtensions,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the ServerMetadataQuery when eager-loading is set.
|
||||
Edges ServerMetadataEdges `json:"edges"`
|
||||
server_metadata_follower *uuid.UUID
|
||||
server_metadata_followee *uuid.UUID
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// ServerMetadataEdges holds the relations/edges for other nodes in the graph.
|
||||
type ServerMetadataEdges struct {
|
||||
// Follower holds the value of the follower edge.
|
||||
Follower *User `json:"follower,omitempty"`
|
||||
// Followee holds the value of the followee edge.
|
||||
Followee *User `json:"followee,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [2]bool
|
||||
}
|
||||
|
||||
// FollowerOrErr returns the Follower value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e ServerMetadataEdges) FollowerOrErr() (*User, error) {
|
||||
if e.Follower != nil {
|
||||
return e.Follower, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "follower"}
|
||||
}
|
||||
|
||||
// FolloweeOrErr returns the Followee value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e ServerMetadataEdges) FolloweeOrErr() (*User, error) {
|
||||
if e.Followee != nil {
|
||||
return e.Followee, nil
|
||||
} else if e.loadedTypes[1] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "followee"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*ServerMetadata) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case servermetadata.FieldExtensions, servermetadata.FieldSupportedExtensions:
|
||||
values[i] = new([]byte)
|
||||
case servermetadata.FieldIsRemote:
|
||||
values[i] = new(sql.NullBool)
|
||||
case servermetadata.FieldURI, servermetadata.FieldName, servermetadata.FieldDescription, servermetadata.FieldVersion:
|
||||
values[i] = new(sql.NullString)
|
||||
case servermetadata.FieldCreatedAt, servermetadata.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
case servermetadata.FieldID:
|
||||
values[i] = new(uuid.UUID)
|
||||
case servermetadata.ForeignKeys[0]: // server_metadata_follower
|
||||
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
||||
case servermetadata.ForeignKeys[1]: // server_metadata_followee
|
||||
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the ServerMetadata fields.
|
||||
func (sm *ServerMetadata) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case servermetadata.FieldID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||
} else if value != nil {
|
||||
sm.ID = *value
|
||||
}
|
||||
case servermetadata.FieldIsRemote:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field isRemote", values[i])
|
||||
} else if value.Valid {
|
||||
sm.IsRemote = value.Bool
|
||||
}
|
||||
case servermetadata.FieldURI:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uri", values[i])
|
||||
} else if value.Valid {
|
||||
sm.URI = value.String
|
||||
}
|
||||
case servermetadata.FieldExtensions:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field extensions", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &sm.Extensions); err != nil {
|
||||
return fmt.Errorf("unmarshal field extensions: %w", err)
|
||||
}
|
||||
}
|
||||
case servermetadata.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
sm.CreatedAt = value.Time
|
||||
}
|
||||
case servermetadata.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
sm.UpdatedAt = value.Time
|
||||
}
|
||||
case servermetadata.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
sm.Name = value.String
|
||||
}
|
||||
case servermetadata.FieldDescription:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field description", values[i])
|
||||
} else if value.Valid {
|
||||
sm.Description = new(string)
|
||||
*sm.Description = value.String
|
||||
}
|
||||
case servermetadata.FieldVersion:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field version", values[i])
|
||||
} else if value.Valid {
|
||||
sm.Version = value.String
|
||||
}
|
||||
case servermetadata.FieldSupportedExtensions:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field supportedExtensions", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &sm.SupportedExtensions); err != nil {
|
||||
return fmt.Errorf("unmarshal field supportedExtensions: %w", err)
|
||||
}
|
||||
}
|
||||
case servermetadata.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullScanner); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field server_metadata_follower", values[i])
|
||||
} else if value.Valid {
|
||||
sm.server_metadata_follower = new(uuid.UUID)
|
||||
*sm.server_metadata_follower = *value.S.(*uuid.UUID)
|
||||
}
|
||||
case servermetadata.ForeignKeys[1]:
|
||||
if value, ok := values[i].(*sql.NullScanner); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field server_metadata_followee", values[i])
|
||||
} else if value.Valid {
|
||||
sm.server_metadata_followee = new(uuid.UUID)
|
||||
*sm.server_metadata_followee = *value.S.(*uuid.UUID)
|
||||
}
|
||||
default:
|
||||
sm.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the ServerMetadata.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (sm *ServerMetadata) Value(name string) (ent.Value, error) {
|
||||
return sm.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryFollower queries the "follower" edge of the ServerMetadata entity.
|
||||
func (sm *ServerMetadata) QueryFollower() *UserQuery {
|
||||
return NewServerMetadataClient(sm.config).QueryFollower(sm)
|
||||
}
|
||||
|
||||
// QueryFollowee queries the "followee" edge of the ServerMetadata entity.
|
||||
func (sm *ServerMetadata) QueryFollowee() *UserQuery {
|
||||
return NewServerMetadataClient(sm.config).QueryFollowee(sm)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this ServerMetadata.
|
||||
// Note that you need to call ServerMetadata.Unwrap() before calling this method if this ServerMetadata
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (sm *ServerMetadata) Update() *ServerMetadataUpdateOne {
|
||||
return NewServerMetadataClient(sm.config).UpdateOne(sm)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the ServerMetadata entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (sm *ServerMetadata) Unwrap() *ServerMetadata {
|
||||
_tx, ok := sm.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: ServerMetadata is not a transactional entity")
|
||||
}
|
||||
sm.config.driver = _tx.drv
|
||||
return sm
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (sm *ServerMetadata) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("ServerMetadata(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", sm.ID))
|
||||
builder.WriteString("isRemote=")
|
||||
builder.WriteString(fmt.Sprintf("%v", sm.IsRemote))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uri=")
|
||||
builder.WriteString(sm.URI)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("extensions=")
|
||||
builder.WriteString(fmt.Sprintf("%v", sm.Extensions))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(sm.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(sm.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(sm.Name)
|
||||
builder.WriteString(", ")
|
||||
if v := sm.Description; v != nil {
|
||||
builder.WriteString("description=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("version=")
|
||||
builder.WriteString(sm.Version)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("supportedExtensions=")
|
||||
builder.WriteString(fmt.Sprintf("%v", sm.SupportedExtensions))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// ServerMetadataSlice is a parsable slice of ServerMetadata.
|
||||
type ServerMetadataSlice []*ServerMetadata
|
||||
185
ent/servermetadata/servermetadata.go
Normal file
185
ent/servermetadata/servermetadata.go
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package servermetadata
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the servermetadata type in the database.
|
||||
Label = "server_metadata"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldIsRemote holds the string denoting the isremote field in the database.
|
||||
FieldIsRemote = "is_remote"
|
||||
// FieldURI holds the string denoting the uri field in the database.
|
||||
FieldURI = "uri"
|
||||
// FieldExtensions holds the string denoting the extensions field in the database.
|
||||
FieldExtensions = "extensions"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldDescription holds the string denoting the description field in the database.
|
||||
FieldDescription = "description"
|
||||
// FieldVersion holds the string denoting the version field in the database.
|
||||
FieldVersion = "version"
|
||||
// FieldSupportedExtensions holds the string denoting the supportedextensions field in the database.
|
||||
FieldSupportedExtensions = "supported_extensions"
|
||||
// EdgeFollower holds the string denoting the follower edge name in mutations.
|
||||
EdgeFollower = "follower"
|
||||
// EdgeFollowee holds the string denoting the followee edge name in mutations.
|
||||
EdgeFollowee = "followee"
|
||||
// Table holds the table name of the servermetadata in the database.
|
||||
Table = "server_metadata"
|
||||
// FollowerTable is the table that holds the follower relation/edge.
|
||||
FollowerTable = "server_metadata"
|
||||
// FollowerInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
FollowerInverseTable = "users"
|
||||
// FollowerColumn is the table column denoting the follower relation/edge.
|
||||
FollowerColumn = "server_metadata_follower"
|
||||
// FolloweeTable is the table that holds the followee relation/edge.
|
||||
FolloweeTable = "server_metadata"
|
||||
// FolloweeInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
FolloweeInverseTable = "users"
|
||||
// FolloweeColumn is the table column denoting the followee relation/edge.
|
||||
FolloweeColumn = "server_metadata_followee"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for servermetadata fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldIsRemote,
|
||||
FieldURI,
|
||||
FieldExtensions,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldName,
|
||||
FieldDescription,
|
||||
FieldVersion,
|
||||
FieldSupportedExtensions,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "server_metadata"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"server_metadata_follower",
|
||||
"server_metadata_followee",
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
URIValidator func(string) error
|
||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
||||
DefaultExtensions lysand.Extensions
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time
|
||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||
UpdateDefaultUpdatedAt func() time.Time
|
||||
// NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||
NameValidator func(string) error
|
||||
// VersionValidator is a validator for the "version" field. It is called by the builders before save.
|
||||
VersionValidator func(string) error
|
||||
// DefaultSupportedExtensions holds the default value on creation for the "supportedExtensions" field.
|
||||
DefaultSupportedExtensions []string
|
||||
// DefaultID holds the default value on creation for the "id" field.
|
||||
DefaultID func() uuid.UUID
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the ServerMetadata queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByIsRemote orders the results by the isRemote field.
|
||||
func ByIsRemote(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldIsRemote, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByURI orders the results by the uri field.
|
||||
func ByURI(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldURI, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDescription orders the results by the description field.
|
||||
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDescription, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByVersion orders the results by the version field.
|
||||
func ByVersion(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldVersion, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByFollowerField orders the results by follower field.
|
||||
func ByFollowerField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newFollowerStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByFolloweeField orders the results by followee field.
|
||||
func ByFolloweeField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newFolloweeStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newFollowerStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(FollowerInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, FollowerTable, FollowerColumn),
|
||||
)
|
||||
}
|
||||
func newFolloweeStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(FolloweeInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, FolloweeTable, FolloweeColumn),
|
||||
)
|
||||
}
|
||||
513
ent/servermetadata/where.go
Normal file
513
ent/servermetadata/where.go
Normal file
|
|
@ -0,0 +1,513 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package servermetadata
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id uuid.UUID) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id uuid.UUID) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id uuid.UUID) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...uuid.UUID) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...uuid.UUID) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id uuid.UUID) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id uuid.UUID) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id uuid.UUID) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id uuid.UUID) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IsRemote applies equality check predicate on the "isRemote" field. It's identical to IsRemoteEQ.
|
||||
func IsRemote(v bool) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldIsRemote, v))
|
||||
}
|
||||
|
||||
// URI applies equality check predicate on the "uri" field. It's identical to URIEQ.
|
||||
func URI(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldURI, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
|
||||
func Description(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// Version applies equality check predicate on the "version" field. It's identical to VersionEQ.
|
||||
func Version(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldVersion, v))
|
||||
}
|
||||
|
||||
// IsRemoteEQ applies the EQ predicate on the "isRemote" field.
|
||||
func IsRemoteEQ(v bool) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldIsRemote, v))
|
||||
}
|
||||
|
||||
// IsRemoteNEQ applies the NEQ predicate on the "isRemote" field.
|
||||
func IsRemoteNEQ(v bool) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNEQ(FieldIsRemote, v))
|
||||
}
|
||||
|
||||
// URIEQ applies the EQ predicate on the "uri" field.
|
||||
func URIEQ(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldURI, v))
|
||||
}
|
||||
|
||||
// URINEQ applies the NEQ predicate on the "uri" field.
|
||||
func URINEQ(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNEQ(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIIn applies the In predicate on the "uri" field.
|
||||
func URIIn(vs ...string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldIn(FieldURI, vs...))
|
||||
}
|
||||
|
||||
// URINotIn applies the NotIn predicate on the "uri" field.
|
||||
func URINotIn(vs ...string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNotIn(FieldURI, vs...))
|
||||
}
|
||||
|
||||
// URIGT applies the GT predicate on the "uri" field.
|
||||
func URIGT(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGT(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIGTE applies the GTE predicate on the "uri" field.
|
||||
func URIGTE(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGTE(FieldURI, v))
|
||||
}
|
||||
|
||||
// URILT applies the LT predicate on the "uri" field.
|
||||
func URILT(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLT(FieldURI, v))
|
||||
}
|
||||
|
||||
// URILTE applies the LTE predicate on the "uri" field.
|
||||
func URILTE(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLTE(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIContains applies the Contains predicate on the "uri" field.
|
||||
func URIContains(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldContains(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIHasPrefix applies the HasPrefix predicate on the "uri" field.
|
||||
func URIHasPrefix(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldHasPrefix(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIHasSuffix applies the HasSuffix predicate on the "uri" field.
|
||||
func URIHasSuffix(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldHasSuffix(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIEqualFold applies the EqualFold predicate on the "uri" field.
|
||||
func URIEqualFold(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEqualFold(FieldURI, v))
|
||||
}
|
||||
|
||||
// URIContainsFold applies the ContainsFold predicate on the "uri" field.
|
||||
func URIContainsFold(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldContainsFold(FieldURI, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// DescriptionEQ applies the EQ predicate on the "description" field.
|
||||
func DescriptionEQ(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionNEQ applies the NEQ predicate on the "description" field.
|
||||
func DescriptionNEQ(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionIn applies the In predicate on the "description" field.
|
||||
func DescriptionIn(vs ...string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldIn(FieldDescription, vs...))
|
||||
}
|
||||
|
||||
// DescriptionNotIn applies the NotIn predicate on the "description" field.
|
||||
func DescriptionNotIn(vs ...string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNotIn(FieldDescription, vs...))
|
||||
}
|
||||
|
||||
// DescriptionGT applies the GT predicate on the "description" field.
|
||||
func DescriptionGT(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGT(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionGTE applies the GTE predicate on the "description" field.
|
||||
func DescriptionGTE(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGTE(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionLT applies the LT predicate on the "description" field.
|
||||
func DescriptionLT(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLT(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionLTE applies the LTE predicate on the "description" field.
|
||||
func DescriptionLTE(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLTE(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionContains applies the Contains predicate on the "description" field.
|
||||
func DescriptionContains(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldContains(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
|
||||
func DescriptionHasPrefix(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldHasPrefix(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
|
||||
func DescriptionHasSuffix(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldHasSuffix(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionIsNil applies the IsNil predicate on the "description" field.
|
||||
func DescriptionIsNil() predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldIsNull(FieldDescription))
|
||||
}
|
||||
|
||||
// DescriptionNotNil applies the NotNil predicate on the "description" field.
|
||||
func DescriptionNotNil() predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNotNull(FieldDescription))
|
||||
}
|
||||
|
||||
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
|
||||
func DescriptionEqualFold(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEqualFold(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
|
||||
func DescriptionContainsFold(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldContainsFold(FieldDescription, v))
|
||||
}
|
||||
|
||||
// VersionEQ applies the EQ predicate on the "version" field.
|
||||
func VersionEQ(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEQ(FieldVersion, v))
|
||||
}
|
||||
|
||||
// VersionNEQ applies the NEQ predicate on the "version" field.
|
||||
func VersionNEQ(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNEQ(FieldVersion, v))
|
||||
}
|
||||
|
||||
// VersionIn applies the In predicate on the "version" field.
|
||||
func VersionIn(vs ...string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldIn(FieldVersion, vs...))
|
||||
}
|
||||
|
||||
// VersionNotIn applies the NotIn predicate on the "version" field.
|
||||
func VersionNotIn(vs ...string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldNotIn(FieldVersion, vs...))
|
||||
}
|
||||
|
||||
// VersionGT applies the GT predicate on the "version" field.
|
||||
func VersionGT(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGT(FieldVersion, v))
|
||||
}
|
||||
|
||||
// VersionGTE applies the GTE predicate on the "version" field.
|
||||
func VersionGTE(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldGTE(FieldVersion, v))
|
||||
}
|
||||
|
||||
// VersionLT applies the LT predicate on the "version" field.
|
||||
func VersionLT(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLT(FieldVersion, v))
|
||||
}
|
||||
|
||||
// VersionLTE applies the LTE predicate on the "version" field.
|
||||
func VersionLTE(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldLTE(FieldVersion, v))
|
||||
}
|
||||
|
||||
// VersionContains applies the Contains predicate on the "version" field.
|
||||
func VersionContains(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldContains(FieldVersion, v))
|
||||
}
|
||||
|
||||
// VersionHasPrefix applies the HasPrefix predicate on the "version" field.
|
||||
func VersionHasPrefix(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldHasPrefix(FieldVersion, v))
|
||||
}
|
||||
|
||||
// VersionHasSuffix applies the HasSuffix predicate on the "version" field.
|
||||
func VersionHasSuffix(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldHasSuffix(FieldVersion, v))
|
||||
}
|
||||
|
||||
// VersionEqualFold applies the EqualFold predicate on the "version" field.
|
||||
func VersionEqualFold(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldEqualFold(FieldVersion, v))
|
||||
}
|
||||
|
||||
// VersionContainsFold applies the ContainsFold predicate on the "version" field.
|
||||
func VersionContainsFold(v string) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.FieldContainsFold(FieldVersion, v))
|
||||
}
|
||||
|
||||
// HasFollower applies the HasEdge predicate on the "follower" edge.
|
||||
func HasFollower() predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, FollowerTable, FollowerColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasFollowerWith applies the HasEdge predicate on the "follower" edge with a given conditions (other predicates).
|
||||
func HasFollowerWith(preds ...predicate.User) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(func(s *sql.Selector) {
|
||||
step := newFollowerStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasFollowee applies the HasEdge predicate on the "followee" edge.
|
||||
func HasFollowee() predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, FolloweeTable, FolloweeColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasFolloweeWith applies the HasEdge predicate on the "followee" edge with a given conditions (other predicates).
|
||||
func HasFolloweeWith(preds ...predicate.User) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(func(s *sql.Selector) {
|
||||
step := newFolloweeStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.ServerMetadata) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.ServerMetadata) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.ServerMetadata) predicate.ServerMetadata {
|
||||
return predicate.ServerMetadata(sql.NotPredicates(p))
|
||||
}
|
||||
1035
ent/servermetadata_create.go
Normal file
1035
ent/servermetadata_create.go
Normal file
File diff suppressed because it is too large
Load diff
88
ent/servermetadata_delete.go
Normal file
88
ent/servermetadata_delete.go
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/servermetadata"
|
||||
)
|
||||
|
||||
// ServerMetadataDelete is the builder for deleting a ServerMetadata entity.
|
||||
type ServerMetadataDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ServerMetadataMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ServerMetadataDelete builder.
|
||||
func (smd *ServerMetadataDelete) Where(ps ...predicate.ServerMetadata) *ServerMetadataDelete {
|
||||
smd.mutation.Where(ps...)
|
||||
return smd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (smd *ServerMetadataDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, smd.sqlExec, smd.mutation, smd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (smd *ServerMetadataDelete) ExecX(ctx context.Context) int {
|
||||
n, err := smd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (smd *ServerMetadataDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(servermetadata.Table, sqlgraph.NewFieldSpec(servermetadata.FieldID, field.TypeUUID))
|
||||
if ps := smd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, smd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
smd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// ServerMetadataDeleteOne is the builder for deleting a single ServerMetadata entity.
|
||||
type ServerMetadataDeleteOne struct {
|
||||
smd *ServerMetadataDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ServerMetadataDelete builder.
|
||||
func (smdo *ServerMetadataDeleteOne) Where(ps ...predicate.ServerMetadata) *ServerMetadataDeleteOne {
|
||||
smdo.smd.mutation.Where(ps...)
|
||||
return smdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (smdo *ServerMetadataDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := smdo.smd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{servermetadata.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (smdo *ServerMetadataDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := smdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
688
ent/servermetadata_query.go
Normal file
688
ent/servermetadata_query.go
Normal file
|
|
@ -0,0 +1,688 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/servermetadata"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
)
|
||||
|
||||
// ServerMetadataQuery is the builder for querying ServerMetadata entities.
|
||||
type ServerMetadataQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []servermetadata.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.ServerMetadata
|
||||
withFollower *UserQuery
|
||||
withFollowee *UserQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the ServerMetadataQuery builder.
|
||||
func (smq *ServerMetadataQuery) Where(ps ...predicate.ServerMetadata) *ServerMetadataQuery {
|
||||
smq.predicates = append(smq.predicates, ps...)
|
||||
return smq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (smq *ServerMetadataQuery) Limit(limit int) *ServerMetadataQuery {
|
||||
smq.ctx.Limit = &limit
|
||||
return smq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (smq *ServerMetadataQuery) Offset(offset int) *ServerMetadataQuery {
|
||||
smq.ctx.Offset = &offset
|
||||
return smq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (smq *ServerMetadataQuery) Unique(unique bool) *ServerMetadataQuery {
|
||||
smq.ctx.Unique = &unique
|
||||
return smq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (smq *ServerMetadataQuery) Order(o ...servermetadata.OrderOption) *ServerMetadataQuery {
|
||||
smq.order = append(smq.order, o...)
|
||||
return smq
|
||||
}
|
||||
|
||||
// QueryFollower chains the current query on the "follower" edge.
|
||||
func (smq *ServerMetadataQuery) QueryFollower() *UserQuery {
|
||||
query := (&UserClient{config: smq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := smq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := smq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(servermetadata.Table, servermetadata.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, servermetadata.FollowerTable, servermetadata.FollowerColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(smq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryFollowee chains the current query on the "followee" edge.
|
||||
func (smq *ServerMetadataQuery) QueryFollowee() *UserQuery {
|
||||
query := (&UserClient{config: smq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := smq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := smq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(servermetadata.Table, servermetadata.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, servermetadata.FolloweeTable, servermetadata.FolloweeColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(smq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first ServerMetadata entity from the query.
|
||||
// Returns a *NotFoundError when no ServerMetadata was found.
|
||||
func (smq *ServerMetadataQuery) First(ctx context.Context) (*ServerMetadata, error) {
|
||||
nodes, err := smq.Limit(1).All(setContextOp(ctx, smq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{servermetadata.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (smq *ServerMetadataQuery) FirstX(ctx context.Context) *ServerMetadata {
|
||||
node, err := smq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first ServerMetadata ID from the query.
|
||||
// Returns a *NotFoundError when no ServerMetadata ID was found.
|
||||
func (smq *ServerMetadataQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = smq.Limit(1).IDs(setContextOp(ctx, smq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{servermetadata.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (smq *ServerMetadataQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := smq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single ServerMetadata entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one ServerMetadata entity is found.
|
||||
// Returns a *NotFoundError when no ServerMetadata entities are found.
|
||||
func (smq *ServerMetadataQuery) Only(ctx context.Context) (*ServerMetadata, error) {
|
||||
nodes, err := smq.Limit(2).All(setContextOp(ctx, smq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{servermetadata.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{servermetadata.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (smq *ServerMetadataQuery) OnlyX(ctx context.Context) *ServerMetadata {
|
||||
node, err := smq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only ServerMetadata ID in the query.
|
||||
// Returns a *NotSingularError when more than one ServerMetadata ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (smq *ServerMetadataQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = smq.Limit(2).IDs(setContextOp(ctx, smq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{servermetadata.Label}
|
||||
default:
|
||||
err = &NotSingularError{servermetadata.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (smq *ServerMetadataQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := smq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of ServerMetadataSlice.
|
||||
func (smq *ServerMetadataQuery) All(ctx context.Context) ([]*ServerMetadata, error) {
|
||||
ctx = setContextOp(ctx, smq.ctx, "All")
|
||||
if err := smq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*ServerMetadata, *ServerMetadataQuery]()
|
||||
return withInterceptors[[]*ServerMetadata](ctx, smq, qr, smq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (smq *ServerMetadataQuery) AllX(ctx context.Context) []*ServerMetadata {
|
||||
nodes, err := smq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of ServerMetadata IDs.
|
||||
func (smq *ServerMetadataQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||
if smq.ctx.Unique == nil && smq.path != nil {
|
||||
smq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, smq.ctx, "IDs")
|
||||
if err = smq.Select(servermetadata.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (smq *ServerMetadataQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||
ids, err := smq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (smq *ServerMetadataQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, smq.ctx, "Count")
|
||||
if err := smq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, smq, querierCount[*ServerMetadataQuery](), smq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (smq *ServerMetadataQuery) CountX(ctx context.Context) int {
|
||||
count, err := smq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (smq *ServerMetadataQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, smq.ctx, "Exist")
|
||||
switch _, err := smq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (smq *ServerMetadataQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := smq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the ServerMetadataQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (smq *ServerMetadataQuery) Clone() *ServerMetadataQuery {
|
||||
if smq == nil {
|
||||
return nil
|
||||
}
|
||||
return &ServerMetadataQuery{
|
||||
config: smq.config,
|
||||
ctx: smq.ctx.Clone(),
|
||||
order: append([]servermetadata.OrderOption{}, smq.order...),
|
||||
inters: append([]Interceptor{}, smq.inters...),
|
||||
predicates: append([]predicate.ServerMetadata{}, smq.predicates...),
|
||||
withFollower: smq.withFollower.Clone(),
|
||||
withFollowee: smq.withFollowee.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: smq.sql.Clone(),
|
||||
path: smq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithFollower tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "follower" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (smq *ServerMetadataQuery) WithFollower(opts ...func(*UserQuery)) *ServerMetadataQuery {
|
||||
query := (&UserClient{config: smq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
smq.withFollower = query
|
||||
return smq
|
||||
}
|
||||
|
||||
// WithFollowee tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "followee" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (smq *ServerMetadataQuery) WithFollowee(opts ...func(*UserQuery)) *ServerMetadataQuery {
|
||||
query := (&UserClient{config: smq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
smq.withFollowee = query
|
||||
return smq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// IsRemote bool `json:"isRemote,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.ServerMetadata.Query().
|
||||
// GroupBy(servermetadata.FieldIsRemote).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (smq *ServerMetadataQuery) GroupBy(field string, fields ...string) *ServerMetadataGroupBy {
|
||||
smq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &ServerMetadataGroupBy{build: smq}
|
||||
grbuild.flds = &smq.ctx.Fields
|
||||
grbuild.label = servermetadata.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// IsRemote bool `json:"isRemote,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.ServerMetadata.Query().
|
||||
// Select(servermetadata.FieldIsRemote).
|
||||
// Scan(ctx, &v)
|
||||
func (smq *ServerMetadataQuery) Select(fields ...string) *ServerMetadataSelect {
|
||||
smq.ctx.Fields = append(smq.ctx.Fields, fields...)
|
||||
sbuild := &ServerMetadataSelect{ServerMetadataQuery: smq}
|
||||
sbuild.label = servermetadata.Label
|
||||
sbuild.flds, sbuild.scan = &smq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a ServerMetadataSelect configured with the given aggregations.
|
||||
func (smq *ServerMetadataQuery) Aggregate(fns ...AggregateFunc) *ServerMetadataSelect {
|
||||
return smq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (smq *ServerMetadataQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range smq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, smq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range smq.ctx.Fields {
|
||||
if !servermetadata.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if smq.path != nil {
|
||||
prev, err := smq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
smq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (smq *ServerMetadataQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ServerMetadata, error) {
|
||||
var (
|
||||
nodes = []*ServerMetadata{}
|
||||
withFKs = smq.withFKs
|
||||
_spec = smq.querySpec()
|
||||
loadedTypes = [2]bool{
|
||||
smq.withFollower != nil,
|
||||
smq.withFollowee != nil,
|
||||
}
|
||||
)
|
||||
if smq.withFollower != nil || smq.withFollowee != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, servermetadata.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*ServerMetadata).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &ServerMetadata{config: smq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, smq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := smq.withFollower; query != nil {
|
||||
if err := smq.loadFollower(ctx, query, nodes, nil,
|
||||
func(n *ServerMetadata, e *User) { n.Edges.Follower = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := smq.withFollowee; query != nil {
|
||||
if err := smq.loadFollowee(ctx, query, nodes, nil,
|
||||
func(n *ServerMetadata, e *User) { n.Edges.Followee = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (smq *ServerMetadataQuery) loadFollower(ctx context.Context, query *UserQuery, nodes []*ServerMetadata, init func(*ServerMetadata), assign func(*ServerMetadata, *User)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*ServerMetadata)
|
||||
for i := range nodes {
|
||||
if nodes[i].server_metadata_follower == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].server_metadata_follower
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "server_metadata_follower" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (smq *ServerMetadataQuery) loadFollowee(ctx context.Context, query *UserQuery, nodes []*ServerMetadata, init func(*ServerMetadata), assign func(*ServerMetadata, *User)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*ServerMetadata)
|
||||
for i := range nodes {
|
||||
if nodes[i].server_metadata_followee == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].server_metadata_followee
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "server_metadata_followee" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (smq *ServerMetadataQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := smq.querySpec()
|
||||
_spec.Node.Columns = smq.ctx.Fields
|
||||
if len(smq.ctx.Fields) > 0 {
|
||||
_spec.Unique = smq.ctx.Unique != nil && *smq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, smq.driver, _spec)
|
||||
}
|
||||
|
||||
func (smq *ServerMetadataQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(servermetadata.Table, servermetadata.Columns, sqlgraph.NewFieldSpec(servermetadata.FieldID, field.TypeUUID))
|
||||
_spec.From = smq.sql
|
||||
if unique := smq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if smq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := smq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, servermetadata.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != servermetadata.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := smq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := smq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := smq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := smq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (smq *ServerMetadataQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(smq.driver.Dialect())
|
||||
t1 := builder.Table(servermetadata.Table)
|
||||
columns := smq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = servermetadata.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if smq.sql != nil {
|
||||
selector = smq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if smq.ctx.Unique != nil && *smq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range smq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range smq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := smq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := smq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ServerMetadataGroupBy is the group-by builder for ServerMetadata entities.
|
||||
type ServerMetadataGroupBy struct {
|
||||
selector
|
||||
build *ServerMetadataQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (smgb *ServerMetadataGroupBy) Aggregate(fns ...AggregateFunc) *ServerMetadataGroupBy {
|
||||
smgb.fns = append(smgb.fns, fns...)
|
||||
return smgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (smgb *ServerMetadataGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, smgb.build.ctx, "GroupBy")
|
||||
if err := smgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*ServerMetadataQuery, *ServerMetadataGroupBy](ctx, smgb.build, smgb, smgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (smgb *ServerMetadataGroupBy) sqlScan(ctx context.Context, root *ServerMetadataQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(smgb.fns))
|
||||
for _, fn := range smgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*smgb.flds)+len(smgb.fns))
|
||||
for _, f := range *smgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*smgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := smgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// ServerMetadataSelect is the builder for selecting fields of ServerMetadata entities.
|
||||
type ServerMetadataSelect struct {
|
||||
*ServerMetadataQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (sms *ServerMetadataSelect) Aggregate(fns ...AggregateFunc) *ServerMetadataSelect {
|
||||
sms.fns = append(sms.fns, fns...)
|
||||
return sms
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (sms *ServerMetadataSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, sms.ctx, "Select")
|
||||
if err := sms.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*ServerMetadataQuery, *ServerMetadataSelect](ctx, sms.ServerMetadataQuery, sms, sms.inters, v)
|
||||
}
|
||||
|
||||
func (sms *ServerMetadataSelect) sqlScan(ctx context.Context, root *ServerMetadataQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(sms.fns))
|
||||
for _, fn := range sms.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*sms.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := sms.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
704
ent/servermetadata_update.go
Normal file
704
ent/servermetadata_update.go
Normal file
|
|
@ -0,0 +1,704 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/dialect/sql/sqljson"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/servermetadata"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
// ServerMetadataUpdate is the builder for updating ServerMetadata entities.
|
||||
type ServerMetadataUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ServerMetadataMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ServerMetadataUpdate builder.
|
||||
func (smu *ServerMetadataUpdate) Where(ps ...predicate.ServerMetadata) *ServerMetadataUpdate {
|
||||
smu.mutation.Where(ps...)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetIsRemote sets the "isRemote" field.
|
||||
func (smu *ServerMetadataUpdate) SetIsRemote(b bool) *ServerMetadataUpdate {
|
||||
smu.mutation.SetIsRemote(b)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetNillableIsRemote sets the "isRemote" field if the given value is not nil.
|
||||
func (smu *ServerMetadataUpdate) SetNillableIsRemote(b *bool) *ServerMetadataUpdate {
|
||||
if b != nil {
|
||||
smu.SetIsRemote(*b)
|
||||
}
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetURI sets the "uri" field.
|
||||
func (smu *ServerMetadataUpdate) SetURI(s string) *ServerMetadataUpdate {
|
||||
smu.mutation.SetURI(s)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetNillableURI sets the "uri" field if the given value is not nil.
|
||||
func (smu *ServerMetadataUpdate) SetNillableURI(s *string) *ServerMetadataUpdate {
|
||||
if s != nil {
|
||||
smu.SetURI(*s)
|
||||
}
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (smu *ServerMetadataUpdate) SetExtensions(l lysand.Extensions) *ServerMetadataUpdate {
|
||||
smu.mutation.SetExtensions(l)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (smu *ServerMetadataUpdate) SetUpdatedAt(t time.Time) *ServerMetadataUpdate {
|
||||
smu.mutation.SetUpdatedAt(t)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (smu *ServerMetadataUpdate) SetName(s string) *ServerMetadataUpdate {
|
||||
smu.mutation.SetName(s)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (smu *ServerMetadataUpdate) SetNillableName(s *string) *ServerMetadataUpdate {
|
||||
if s != nil {
|
||||
smu.SetName(*s)
|
||||
}
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (smu *ServerMetadataUpdate) SetDescription(s string) *ServerMetadataUpdate {
|
||||
smu.mutation.SetDescription(s)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (smu *ServerMetadataUpdate) SetNillableDescription(s *string) *ServerMetadataUpdate {
|
||||
if s != nil {
|
||||
smu.SetDescription(*s)
|
||||
}
|
||||
return smu
|
||||
}
|
||||
|
||||
// ClearDescription clears the value of the "description" field.
|
||||
func (smu *ServerMetadataUpdate) ClearDescription() *ServerMetadataUpdate {
|
||||
smu.mutation.ClearDescription()
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetVersion sets the "version" field.
|
||||
func (smu *ServerMetadataUpdate) SetVersion(s string) *ServerMetadataUpdate {
|
||||
smu.mutation.SetVersion(s)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetNillableVersion sets the "version" field if the given value is not nil.
|
||||
func (smu *ServerMetadataUpdate) SetNillableVersion(s *string) *ServerMetadataUpdate {
|
||||
if s != nil {
|
||||
smu.SetVersion(*s)
|
||||
}
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetSupportedExtensions sets the "supportedExtensions" field.
|
||||
func (smu *ServerMetadataUpdate) SetSupportedExtensions(s []string) *ServerMetadataUpdate {
|
||||
smu.mutation.SetSupportedExtensions(s)
|
||||
return smu
|
||||
}
|
||||
|
||||
// AppendSupportedExtensions appends s to the "supportedExtensions" field.
|
||||
func (smu *ServerMetadataUpdate) AppendSupportedExtensions(s []string) *ServerMetadataUpdate {
|
||||
smu.mutation.AppendSupportedExtensions(s)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetFollowerID sets the "follower" edge to the User entity by ID.
|
||||
func (smu *ServerMetadataUpdate) SetFollowerID(id uuid.UUID) *ServerMetadataUpdate {
|
||||
smu.mutation.SetFollowerID(id)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetFollower sets the "follower" edge to the User entity.
|
||||
func (smu *ServerMetadataUpdate) SetFollower(u *User) *ServerMetadataUpdate {
|
||||
return smu.SetFollowerID(u.ID)
|
||||
}
|
||||
|
||||
// SetFolloweeID sets the "followee" edge to the User entity by ID.
|
||||
func (smu *ServerMetadataUpdate) SetFolloweeID(id uuid.UUID) *ServerMetadataUpdate {
|
||||
smu.mutation.SetFolloweeID(id)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetFollowee sets the "followee" edge to the User entity.
|
||||
func (smu *ServerMetadataUpdate) SetFollowee(u *User) *ServerMetadataUpdate {
|
||||
return smu.SetFolloweeID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the ServerMetadataMutation object of the builder.
|
||||
func (smu *ServerMetadataUpdate) Mutation() *ServerMetadataMutation {
|
||||
return smu.mutation
|
||||
}
|
||||
|
||||
// ClearFollower clears the "follower" edge to the User entity.
|
||||
func (smu *ServerMetadataUpdate) ClearFollower() *ServerMetadataUpdate {
|
||||
smu.mutation.ClearFollower()
|
||||
return smu
|
||||
}
|
||||
|
||||
// ClearFollowee clears the "followee" edge to the User entity.
|
||||
func (smu *ServerMetadataUpdate) ClearFollowee() *ServerMetadataUpdate {
|
||||
smu.mutation.ClearFollowee()
|
||||
return smu
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (smu *ServerMetadataUpdate) Save(ctx context.Context) (int, error) {
|
||||
smu.defaults()
|
||||
return withHooks(ctx, smu.sqlSave, smu.mutation, smu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (smu *ServerMetadataUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := smu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (smu *ServerMetadataUpdate) Exec(ctx context.Context) error {
|
||||
_, err := smu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (smu *ServerMetadataUpdate) ExecX(ctx context.Context) {
|
||||
if err := smu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (smu *ServerMetadataUpdate) defaults() {
|
||||
if _, ok := smu.mutation.UpdatedAt(); !ok {
|
||||
v := servermetadata.UpdateDefaultUpdatedAt()
|
||||
smu.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (smu *ServerMetadataUpdate) check() error {
|
||||
if v, ok := smu.mutation.URI(); ok {
|
||||
if err := servermetadata.URIValidator(v); err != nil {
|
||||
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "ServerMetadata.uri": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := smu.mutation.Name(); ok {
|
||||
if err := servermetadata.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ServerMetadata.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := smu.mutation.Version(); ok {
|
||||
if err := servermetadata.VersionValidator(v); err != nil {
|
||||
return &ValidationError{Name: "version", err: fmt.Errorf(`ent: validator failed for field "ServerMetadata.version": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := smu.mutation.FollowerID(); smu.mutation.FollowerCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "ServerMetadata.follower"`)
|
||||
}
|
||||
if _, ok := smu.mutation.FolloweeID(); smu.mutation.FolloweeCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "ServerMetadata.followee"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (smu *ServerMetadataUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := smu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(servermetadata.Table, servermetadata.Columns, sqlgraph.NewFieldSpec(servermetadata.FieldID, field.TypeUUID))
|
||||
if ps := smu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := smu.mutation.IsRemote(); ok {
|
||||
_spec.SetField(servermetadata.FieldIsRemote, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := smu.mutation.URI(); ok {
|
||||
_spec.SetField(servermetadata.FieldURI, field.TypeString, value)
|
||||
}
|
||||
if value, ok := smu.mutation.Extensions(); ok {
|
||||
_spec.SetField(servermetadata.FieldExtensions, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := smu.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(servermetadata.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := smu.mutation.Name(); ok {
|
||||
_spec.SetField(servermetadata.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := smu.mutation.Description(); ok {
|
||||
_spec.SetField(servermetadata.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if smu.mutation.DescriptionCleared() {
|
||||
_spec.ClearField(servermetadata.FieldDescription, field.TypeString)
|
||||
}
|
||||
if value, ok := smu.mutation.Version(); ok {
|
||||
_spec.SetField(servermetadata.FieldVersion, field.TypeString, value)
|
||||
}
|
||||
if value, ok := smu.mutation.SupportedExtensions(); ok {
|
||||
_spec.SetField(servermetadata.FieldSupportedExtensions, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := smu.mutation.AppendedSupportedExtensions(); ok {
|
||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||
sqljson.Append(u, servermetadata.FieldSupportedExtensions, value)
|
||||
})
|
||||
}
|
||||
if smu.mutation.FollowerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: servermetadata.FollowerTable,
|
||||
Columns: []string{servermetadata.FollowerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := smu.mutation.FollowerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: servermetadata.FollowerTable,
|
||||
Columns: []string{servermetadata.FollowerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if smu.mutation.FolloweeCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: servermetadata.FolloweeTable,
|
||||
Columns: []string{servermetadata.FolloweeColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := smu.mutation.FolloweeIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: servermetadata.FolloweeTable,
|
||||
Columns: []string{servermetadata.FolloweeColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, smu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{servermetadata.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
smu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// ServerMetadataUpdateOne is the builder for updating a single ServerMetadata entity.
|
||||
type ServerMetadataUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *ServerMetadataMutation
|
||||
}
|
||||
|
||||
// SetIsRemote sets the "isRemote" field.
|
||||
func (smuo *ServerMetadataUpdateOne) SetIsRemote(b bool) *ServerMetadataUpdateOne {
|
||||
smuo.mutation.SetIsRemote(b)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetNillableIsRemote sets the "isRemote" field if the given value is not nil.
|
||||
func (smuo *ServerMetadataUpdateOne) SetNillableIsRemote(b *bool) *ServerMetadataUpdateOne {
|
||||
if b != nil {
|
||||
smuo.SetIsRemote(*b)
|
||||
}
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetURI sets the "uri" field.
|
||||
func (smuo *ServerMetadataUpdateOne) SetURI(s string) *ServerMetadataUpdateOne {
|
||||
smuo.mutation.SetURI(s)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetNillableURI sets the "uri" field if the given value is not nil.
|
||||
func (smuo *ServerMetadataUpdateOne) SetNillableURI(s *string) *ServerMetadataUpdateOne {
|
||||
if s != nil {
|
||||
smuo.SetURI(*s)
|
||||
}
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (smuo *ServerMetadataUpdateOne) SetExtensions(l lysand.Extensions) *ServerMetadataUpdateOne {
|
||||
smuo.mutation.SetExtensions(l)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (smuo *ServerMetadataUpdateOne) SetUpdatedAt(t time.Time) *ServerMetadataUpdateOne {
|
||||
smuo.mutation.SetUpdatedAt(t)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (smuo *ServerMetadataUpdateOne) SetName(s string) *ServerMetadataUpdateOne {
|
||||
smuo.mutation.SetName(s)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (smuo *ServerMetadataUpdateOne) SetNillableName(s *string) *ServerMetadataUpdateOne {
|
||||
if s != nil {
|
||||
smuo.SetName(*s)
|
||||
}
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (smuo *ServerMetadataUpdateOne) SetDescription(s string) *ServerMetadataUpdateOne {
|
||||
smuo.mutation.SetDescription(s)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (smuo *ServerMetadataUpdateOne) SetNillableDescription(s *string) *ServerMetadataUpdateOne {
|
||||
if s != nil {
|
||||
smuo.SetDescription(*s)
|
||||
}
|
||||
return smuo
|
||||
}
|
||||
|
||||
// ClearDescription clears the value of the "description" field.
|
||||
func (smuo *ServerMetadataUpdateOne) ClearDescription() *ServerMetadataUpdateOne {
|
||||
smuo.mutation.ClearDescription()
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetVersion sets the "version" field.
|
||||
func (smuo *ServerMetadataUpdateOne) SetVersion(s string) *ServerMetadataUpdateOne {
|
||||
smuo.mutation.SetVersion(s)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetNillableVersion sets the "version" field if the given value is not nil.
|
||||
func (smuo *ServerMetadataUpdateOne) SetNillableVersion(s *string) *ServerMetadataUpdateOne {
|
||||
if s != nil {
|
||||
smuo.SetVersion(*s)
|
||||
}
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetSupportedExtensions sets the "supportedExtensions" field.
|
||||
func (smuo *ServerMetadataUpdateOne) SetSupportedExtensions(s []string) *ServerMetadataUpdateOne {
|
||||
smuo.mutation.SetSupportedExtensions(s)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// AppendSupportedExtensions appends s to the "supportedExtensions" field.
|
||||
func (smuo *ServerMetadataUpdateOne) AppendSupportedExtensions(s []string) *ServerMetadataUpdateOne {
|
||||
smuo.mutation.AppendSupportedExtensions(s)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetFollowerID sets the "follower" edge to the User entity by ID.
|
||||
func (smuo *ServerMetadataUpdateOne) SetFollowerID(id uuid.UUID) *ServerMetadataUpdateOne {
|
||||
smuo.mutation.SetFollowerID(id)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetFollower sets the "follower" edge to the User entity.
|
||||
func (smuo *ServerMetadataUpdateOne) SetFollower(u *User) *ServerMetadataUpdateOne {
|
||||
return smuo.SetFollowerID(u.ID)
|
||||
}
|
||||
|
||||
// SetFolloweeID sets the "followee" edge to the User entity by ID.
|
||||
func (smuo *ServerMetadataUpdateOne) SetFolloweeID(id uuid.UUID) *ServerMetadataUpdateOne {
|
||||
smuo.mutation.SetFolloweeID(id)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetFollowee sets the "followee" edge to the User entity.
|
||||
func (smuo *ServerMetadataUpdateOne) SetFollowee(u *User) *ServerMetadataUpdateOne {
|
||||
return smuo.SetFolloweeID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the ServerMetadataMutation object of the builder.
|
||||
func (smuo *ServerMetadataUpdateOne) Mutation() *ServerMetadataMutation {
|
||||
return smuo.mutation
|
||||
}
|
||||
|
||||
// ClearFollower clears the "follower" edge to the User entity.
|
||||
func (smuo *ServerMetadataUpdateOne) ClearFollower() *ServerMetadataUpdateOne {
|
||||
smuo.mutation.ClearFollower()
|
||||
return smuo
|
||||
}
|
||||
|
||||
// ClearFollowee clears the "followee" edge to the User entity.
|
||||
func (smuo *ServerMetadataUpdateOne) ClearFollowee() *ServerMetadataUpdateOne {
|
||||
smuo.mutation.ClearFollowee()
|
||||
return smuo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ServerMetadataUpdate builder.
|
||||
func (smuo *ServerMetadataUpdateOne) Where(ps ...predicate.ServerMetadata) *ServerMetadataUpdateOne {
|
||||
smuo.mutation.Where(ps...)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (smuo *ServerMetadataUpdateOne) Select(field string, fields ...string) *ServerMetadataUpdateOne {
|
||||
smuo.fields = append([]string{field}, fields...)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated ServerMetadata entity.
|
||||
func (smuo *ServerMetadataUpdateOne) Save(ctx context.Context) (*ServerMetadata, error) {
|
||||
smuo.defaults()
|
||||
return withHooks(ctx, smuo.sqlSave, smuo.mutation, smuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (smuo *ServerMetadataUpdateOne) SaveX(ctx context.Context) *ServerMetadata {
|
||||
node, err := smuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (smuo *ServerMetadataUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := smuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (smuo *ServerMetadataUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := smuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (smuo *ServerMetadataUpdateOne) defaults() {
|
||||
if _, ok := smuo.mutation.UpdatedAt(); !ok {
|
||||
v := servermetadata.UpdateDefaultUpdatedAt()
|
||||
smuo.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (smuo *ServerMetadataUpdateOne) check() error {
|
||||
if v, ok := smuo.mutation.URI(); ok {
|
||||
if err := servermetadata.URIValidator(v); err != nil {
|
||||
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "ServerMetadata.uri": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := smuo.mutation.Name(); ok {
|
||||
if err := servermetadata.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ServerMetadata.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := smuo.mutation.Version(); ok {
|
||||
if err := servermetadata.VersionValidator(v); err != nil {
|
||||
return &ValidationError{Name: "version", err: fmt.Errorf(`ent: validator failed for field "ServerMetadata.version": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := smuo.mutation.FollowerID(); smuo.mutation.FollowerCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "ServerMetadata.follower"`)
|
||||
}
|
||||
if _, ok := smuo.mutation.FolloweeID(); smuo.mutation.FolloweeCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "ServerMetadata.followee"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (smuo *ServerMetadataUpdateOne) sqlSave(ctx context.Context) (_node *ServerMetadata, err error) {
|
||||
if err := smuo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(servermetadata.Table, servermetadata.Columns, sqlgraph.NewFieldSpec(servermetadata.FieldID, field.TypeUUID))
|
||||
id, ok := smuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ServerMetadata.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := smuo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, servermetadata.FieldID)
|
||||
for _, f := range fields {
|
||||
if !servermetadata.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != servermetadata.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := smuo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := smuo.mutation.IsRemote(); ok {
|
||||
_spec.SetField(servermetadata.FieldIsRemote, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := smuo.mutation.URI(); ok {
|
||||
_spec.SetField(servermetadata.FieldURI, field.TypeString, value)
|
||||
}
|
||||
if value, ok := smuo.mutation.Extensions(); ok {
|
||||
_spec.SetField(servermetadata.FieldExtensions, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := smuo.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(servermetadata.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := smuo.mutation.Name(); ok {
|
||||
_spec.SetField(servermetadata.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := smuo.mutation.Description(); ok {
|
||||
_spec.SetField(servermetadata.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if smuo.mutation.DescriptionCleared() {
|
||||
_spec.ClearField(servermetadata.FieldDescription, field.TypeString)
|
||||
}
|
||||
if value, ok := smuo.mutation.Version(); ok {
|
||||
_spec.SetField(servermetadata.FieldVersion, field.TypeString, value)
|
||||
}
|
||||
if value, ok := smuo.mutation.SupportedExtensions(); ok {
|
||||
_spec.SetField(servermetadata.FieldSupportedExtensions, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := smuo.mutation.AppendedSupportedExtensions(); ok {
|
||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||
sqljson.Append(u, servermetadata.FieldSupportedExtensions, value)
|
||||
})
|
||||
}
|
||||
if smuo.mutation.FollowerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: servermetadata.FollowerTable,
|
||||
Columns: []string{servermetadata.FollowerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := smuo.mutation.FollowerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: servermetadata.FollowerTable,
|
||||
Columns: []string{servermetadata.FollowerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if smuo.mutation.FolloweeCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: servermetadata.FolloweeTable,
|
||||
Columns: []string{servermetadata.FolloweeColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := smuo.mutation.FolloweeIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: servermetadata.FolloweeTable,
|
||||
Columns: []string{servermetadata.FolloweeColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &ServerMetadata{config: smuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, smuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{servermetadata.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
smuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
225
ent/tx.go
Normal file
225
ent/tx.go
Normal file
|
|
@ -0,0 +1,225 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
)
|
||||
|
||||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct {
|
||||
config
|
||||
// Attachment is the client for interacting with the Attachment builders.
|
||||
Attachment *AttachmentClient
|
||||
// Follow is the client for interacting with the Follow builders.
|
||||
Follow *FollowClient
|
||||
// Image is the client for interacting with the Image builders.
|
||||
Image *ImageClient
|
||||
// Note is the client for interacting with the Note builders.
|
||||
Note *NoteClient
|
||||
// ServerMetadata is the client for interacting with the ServerMetadata builders.
|
||||
ServerMetadata *ServerMetadataClient
|
||||
// User is the client for interacting with the User builders.
|
||||
User *UserClient
|
||||
|
||||
// lazily loaded.
|
||||
client *Client
|
||||
clientOnce sync.Once
|
||||
// ctx lives for the life of the transaction. It is
|
||||
// the same context used by the underlying connection.
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
type (
|
||||
// Committer is the interface that wraps the Commit method.
|
||||
Committer interface {
|
||||
Commit(context.Context, *Tx) error
|
||||
}
|
||||
|
||||
// The CommitFunc type is an adapter to allow the use of ordinary
|
||||
// function as a Committer. If f is a function with the appropriate
|
||||
// signature, CommitFunc(f) is a Committer that calls f.
|
||||
CommitFunc func(context.Context, *Tx) error
|
||||
|
||||
// CommitHook defines the "commit middleware". A function that gets a Committer
|
||||
// and returns a Committer. For example:
|
||||
//
|
||||
// hook := func(next ent.Committer) ent.Committer {
|
||||
// return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||
// // Do some stuff before.
|
||||
// if err := next.Commit(ctx, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // Do some stuff after.
|
||||
// return nil
|
||||
// })
|
||||
// }
|
||||
//
|
||||
CommitHook func(Committer) Committer
|
||||
)
|
||||
|
||||
// Commit calls f(ctx, m).
|
||||
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
|
||||
return f(ctx, tx)
|
||||
}
|
||||
|
||||
// Commit commits the transaction.
|
||||
func (tx *Tx) Commit() error {
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
|
||||
return txDriver.tx.Commit()
|
||||
})
|
||||
txDriver.mu.Lock()
|
||||
hooks := append([]CommitHook(nil), txDriver.onCommit...)
|
||||
txDriver.mu.Unlock()
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
fn = hooks[i](fn)
|
||||
}
|
||||
return fn.Commit(tx.ctx, tx)
|
||||
}
|
||||
|
||||
// OnCommit adds a hook to call on commit.
|
||||
func (tx *Tx) OnCommit(f CommitHook) {
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
txDriver.mu.Lock()
|
||||
txDriver.onCommit = append(txDriver.onCommit, f)
|
||||
txDriver.mu.Unlock()
|
||||
}
|
||||
|
||||
type (
|
||||
// Rollbacker is the interface that wraps the Rollback method.
|
||||
Rollbacker interface {
|
||||
Rollback(context.Context, *Tx) error
|
||||
}
|
||||
|
||||
// The RollbackFunc type is an adapter to allow the use of ordinary
|
||||
// function as a Rollbacker. If f is a function with the appropriate
|
||||
// signature, RollbackFunc(f) is a Rollbacker that calls f.
|
||||
RollbackFunc func(context.Context, *Tx) error
|
||||
|
||||
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
|
||||
// and returns a Rollbacker. For example:
|
||||
//
|
||||
// hook := func(next ent.Rollbacker) ent.Rollbacker {
|
||||
// return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||
// // Do some stuff before.
|
||||
// if err := next.Rollback(ctx, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // Do some stuff after.
|
||||
// return nil
|
||||
// })
|
||||
// }
|
||||
//
|
||||
RollbackHook func(Rollbacker) Rollbacker
|
||||
)
|
||||
|
||||
// Rollback calls f(ctx, m).
|
||||
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
|
||||
return f(ctx, tx)
|
||||
}
|
||||
|
||||
// Rollback rollbacks the transaction.
|
||||
func (tx *Tx) Rollback() error {
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
|
||||
return txDriver.tx.Rollback()
|
||||
})
|
||||
txDriver.mu.Lock()
|
||||
hooks := append([]RollbackHook(nil), txDriver.onRollback...)
|
||||
txDriver.mu.Unlock()
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
fn = hooks[i](fn)
|
||||
}
|
||||
return fn.Rollback(tx.ctx, tx)
|
||||
}
|
||||
|
||||
// OnRollback adds a hook to call on rollback.
|
||||
func (tx *Tx) OnRollback(f RollbackHook) {
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
txDriver.mu.Lock()
|
||||
txDriver.onRollback = append(txDriver.onRollback, f)
|
||||
txDriver.mu.Unlock()
|
||||
}
|
||||
|
||||
// Client returns a Client that binds to current transaction.
|
||||
func (tx *Tx) Client() *Client {
|
||||
tx.clientOnce.Do(func() {
|
||||
tx.client = &Client{config: tx.config}
|
||||
tx.client.init()
|
||||
})
|
||||
return tx.client
|
||||
}
|
||||
|
||||
func (tx *Tx) init() {
|
||||
tx.Attachment = NewAttachmentClient(tx.config)
|
||||
tx.Follow = NewFollowClient(tx.config)
|
||||
tx.Image = NewImageClient(tx.config)
|
||||
tx.Note = NewNoteClient(tx.config)
|
||||
tx.ServerMetadata = NewServerMetadataClient(tx.config)
|
||||
tx.User = NewUserClient(tx.config)
|
||||
}
|
||||
|
||||
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
|
||||
// The idea is to support transactions without adding any extra code to the builders.
|
||||
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
|
||||
// Commit and Rollback are nop for the internal builders and the user must call one
|
||||
// of them in order to commit or rollback the transaction.
|
||||
//
|
||||
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||
// applies a query, for example: Attachment.QueryXXX(), the query will be executed
|
||||
// through the driver which created this transaction.
|
||||
//
|
||||
// Note that txDriver is not goroutine safe.
|
||||
type txDriver struct {
|
||||
// the driver we started the transaction from.
|
||||
drv dialect.Driver
|
||||
// tx is the underlying transaction.
|
||||
tx dialect.Tx
|
||||
// completion hooks.
|
||||
mu sync.Mutex
|
||||
onCommit []CommitHook
|
||||
onRollback []RollbackHook
|
||||
}
|
||||
|
||||
// newTx creates a new transactional driver.
|
||||
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
|
||||
tx, err := drv.Tx(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &txDriver{tx: tx, drv: drv}, nil
|
||||
}
|
||||
|
||||
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
|
||||
// from the internal builders. Should be called only by the internal builders.
|
||||
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
|
||||
|
||||
// Dialect returns the dialect of the driver we started the transaction from.
|
||||
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
|
||||
|
||||
// Close is a nop close.
|
||||
func (*txDriver) Close() error { return nil }
|
||||
|
||||
// Commit is a nop commit for the internal builders.
|
||||
// User must call `Tx.Commit` in order to commit the transaction.
|
||||
func (*txDriver) Commit() error { return nil }
|
||||
|
||||
// Rollback is a nop rollback for the internal builders.
|
||||
// User must call `Tx.Rollback` in order to rollback the transaction.
|
||||
func (*txDriver) Rollback() error { return nil }
|
||||
|
||||
// Exec calls tx.Exec.
|
||||
func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error {
|
||||
return tx.tx.Exec(ctx, query, args, v)
|
||||
}
|
||||
|
||||
// Query calls tx.Query.
|
||||
func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error {
|
||||
return tx.tx.Query(ctx, query, args, v)
|
||||
}
|
||||
|
||||
var _ dialect.Driver = (*txDriver)(nil)
|
||||
423
ent/user.go
Normal file
423
ent/user.go
Normal file
|
|
@ -0,0 +1,423 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/image"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
// User is the model entity for the User schema.
|
||||
type User struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID uuid.UUID `json:"id,omitempty"`
|
||||
// IsRemote holds the value of the "isRemote" field.
|
||||
IsRemote bool `json:"isRemote,omitempty"`
|
||||
// URI holds the value of the "uri" field.
|
||||
URI string `json:"uri,omitempty"`
|
||||
// Extensions holds the value of the "extensions" field.
|
||||
Extensions lysand.Extensions `json:"extensions,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// Username holds the value of the "username" field.
|
||||
Username string `json:"username,omitempty"`
|
||||
// PasswordHash holds the value of the "passwordHash" field.
|
||||
PasswordHash *[]byte `json:"passwordHash,omitempty"`
|
||||
// DisplayName holds the value of the "displayName" field.
|
||||
DisplayName *string `json:"displayName,omitempty"`
|
||||
// Biography holds the value of the "biography" field.
|
||||
Biography *string `json:"biography,omitempty"`
|
||||
// PublicKey holds the value of the "publicKey" field.
|
||||
PublicKey ed25519.PublicKey `json:"publicKey,omitempty"`
|
||||
// PrivateKey holds the value of the "privateKey" field.
|
||||
PrivateKey ed25519.PrivateKey `json:"privateKey,omitempty"`
|
||||
// Indexable holds the value of the "indexable" field.
|
||||
Indexable bool `json:"indexable,omitempty"`
|
||||
// PrivacyLevel holds the value of the "privacyLevel" field.
|
||||
PrivacyLevel user.PrivacyLevel `json:"privacyLevel,omitempty"`
|
||||
// Fields holds the value of the "fields" field.
|
||||
Fields []lysand.Field `json:"fields,omitempty"`
|
||||
// Inbox holds the value of the "inbox" field.
|
||||
Inbox string `json:"inbox,omitempty"`
|
||||
// Featured holds the value of the "featured" field.
|
||||
Featured string `json:"featured,omitempty"`
|
||||
// Followers holds the value of the "followers" field.
|
||||
Followers string `json:"followers,omitempty"`
|
||||
// Following holds the value of the "following" field.
|
||||
Following string `json:"following,omitempty"`
|
||||
// Outbox holds the value of the "outbox" field.
|
||||
Outbox string `json:"outbox,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the UserQuery when eager-loading is set.
|
||||
Edges UserEdges `json:"edges"`
|
||||
user_avatar_image *int
|
||||
user_header_image *int
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// UserEdges holds the relations/edges for other nodes in the graph.
|
||||
type UserEdges struct {
|
||||
// AvatarImage holds the value of the avatarImage edge.
|
||||
AvatarImage *Image `json:"avatarImage,omitempty"`
|
||||
// HeaderImage holds the value of the headerImage edge.
|
||||
HeaderImage *Image `json:"headerImage,omitempty"`
|
||||
// AuthoredNotes holds the value of the authoredNotes edge.
|
||||
AuthoredNotes []*Note `json:"authoredNotes,omitempty"`
|
||||
// MentionedNotes holds the value of the mentionedNotes edge.
|
||||
MentionedNotes []*Note `json:"mentionedNotes,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [4]bool
|
||||
}
|
||||
|
||||
// AvatarImageOrErr returns the AvatarImage value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e UserEdges) AvatarImageOrErr() (*Image, error) {
|
||||
if e.AvatarImage != nil {
|
||||
return e.AvatarImage, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: image.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "avatarImage"}
|
||||
}
|
||||
|
||||
// HeaderImageOrErr returns the HeaderImage value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e UserEdges) HeaderImageOrErr() (*Image, error) {
|
||||
if e.HeaderImage != nil {
|
||||
return e.HeaderImage, nil
|
||||
} else if e.loadedTypes[1] {
|
||||
return nil, &NotFoundError{label: image.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "headerImage"}
|
||||
}
|
||||
|
||||
// AuthoredNotesOrErr returns the AuthoredNotes value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserEdges) AuthoredNotesOrErr() ([]*Note, error) {
|
||||
if e.loadedTypes[2] {
|
||||
return e.AuthoredNotes, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "authoredNotes"}
|
||||
}
|
||||
|
||||
// MentionedNotesOrErr returns the MentionedNotes value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserEdges) MentionedNotesOrErr() ([]*Note, error) {
|
||||
if e.loadedTypes[3] {
|
||||
return e.MentionedNotes, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "mentionedNotes"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*User) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case user.FieldExtensions, user.FieldPasswordHash, user.FieldPublicKey, user.FieldPrivateKey, user.FieldFields:
|
||||
values[i] = new([]byte)
|
||||
case user.FieldIsRemote, user.FieldIndexable:
|
||||
values[i] = new(sql.NullBool)
|
||||
case user.FieldURI, user.FieldUsername, user.FieldDisplayName, user.FieldBiography, user.FieldPrivacyLevel, user.FieldInbox, user.FieldFeatured, user.FieldFollowers, user.FieldFollowing, user.FieldOutbox:
|
||||
values[i] = new(sql.NullString)
|
||||
case user.FieldCreatedAt, user.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
case user.FieldID:
|
||||
values[i] = new(uuid.UUID)
|
||||
case user.ForeignKeys[0]: // user_avatar_image
|
||||
values[i] = new(sql.NullInt64)
|
||||
case user.ForeignKeys[1]: // user_header_image
|
||||
values[i] = new(sql.NullInt64)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the User fields.
|
||||
func (u *User) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case user.FieldID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||
} else if value != nil {
|
||||
u.ID = *value
|
||||
}
|
||||
case user.FieldIsRemote:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field isRemote", values[i])
|
||||
} else if value.Valid {
|
||||
u.IsRemote = value.Bool
|
||||
}
|
||||
case user.FieldURI:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uri", values[i])
|
||||
} else if value.Valid {
|
||||
u.URI = value.String
|
||||
}
|
||||
case user.FieldExtensions:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field extensions", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &u.Extensions); err != nil {
|
||||
return fmt.Errorf("unmarshal field extensions: %w", err)
|
||||
}
|
||||
}
|
||||
case user.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
u.CreatedAt = value.Time
|
||||
}
|
||||
case user.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
u.UpdatedAt = value.Time
|
||||
}
|
||||
case user.FieldUsername:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field username", values[i])
|
||||
} else if value.Valid {
|
||||
u.Username = value.String
|
||||
}
|
||||
case user.FieldPasswordHash:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field passwordHash", values[i])
|
||||
} else if value != nil {
|
||||
u.PasswordHash = value
|
||||
}
|
||||
case user.FieldDisplayName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field displayName", values[i])
|
||||
} else if value.Valid {
|
||||
u.DisplayName = new(string)
|
||||
*u.DisplayName = value.String
|
||||
}
|
||||
case user.FieldBiography:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field biography", values[i])
|
||||
} else if value.Valid {
|
||||
u.Biography = new(string)
|
||||
*u.Biography = value.String
|
||||
}
|
||||
case user.FieldPublicKey:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field publicKey", values[i])
|
||||
} else if value != nil {
|
||||
u.PublicKey = *value
|
||||
}
|
||||
case user.FieldPrivateKey:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field privateKey", values[i])
|
||||
} else if value != nil {
|
||||
u.PrivateKey = *value
|
||||
}
|
||||
case user.FieldIndexable:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field indexable", values[i])
|
||||
} else if value.Valid {
|
||||
u.Indexable = value.Bool
|
||||
}
|
||||
case user.FieldPrivacyLevel:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field privacyLevel", values[i])
|
||||
} else if value.Valid {
|
||||
u.PrivacyLevel = user.PrivacyLevel(value.String)
|
||||
}
|
||||
case user.FieldFields:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field fields", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &u.Fields); err != nil {
|
||||
return fmt.Errorf("unmarshal field fields: %w", err)
|
||||
}
|
||||
}
|
||||
case user.FieldInbox:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field inbox", values[i])
|
||||
} else if value.Valid {
|
||||
u.Inbox = value.String
|
||||
}
|
||||
case user.FieldFeatured:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field featured", values[i])
|
||||
} else if value.Valid {
|
||||
u.Featured = value.String
|
||||
}
|
||||
case user.FieldFollowers:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field followers", values[i])
|
||||
} else if value.Valid {
|
||||
u.Followers = value.String
|
||||
}
|
||||
case user.FieldFollowing:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field following", values[i])
|
||||
} else if value.Valid {
|
||||
u.Following = value.String
|
||||
}
|
||||
case user.FieldOutbox:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field outbox", values[i])
|
||||
} else if value.Valid {
|
||||
u.Outbox = value.String
|
||||
}
|
||||
case user.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field user_avatar_image", value)
|
||||
} else if value.Valid {
|
||||
u.user_avatar_image = new(int)
|
||||
*u.user_avatar_image = int(value.Int64)
|
||||
}
|
||||
case user.ForeignKeys[1]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field user_header_image", value)
|
||||
} else if value.Valid {
|
||||
u.user_header_image = new(int)
|
||||
*u.user_header_image = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
u.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the User.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (u *User) Value(name string) (ent.Value, error) {
|
||||
return u.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryAvatarImage queries the "avatarImage" edge of the User entity.
|
||||
func (u *User) QueryAvatarImage() *ImageQuery {
|
||||
return NewUserClient(u.config).QueryAvatarImage(u)
|
||||
}
|
||||
|
||||
// QueryHeaderImage queries the "headerImage" edge of the User entity.
|
||||
func (u *User) QueryHeaderImage() *ImageQuery {
|
||||
return NewUserClient(u.config).QueryHeaderImage(u)
|
||||
}
|
||||
|
||||
// QueryAuthoredNotes queries the "authoredNotes" edge of the User entity.
|
||||
func (u *User) QueryAuthoredNotes() *NoteQuery {
|
||||
return NewUserClient(u.config).QueryAuthoredNotes(u)
|
||||
}
|
||||
|
||||
// QueryMentionedNotes queries the "mentionedNotes" edge of the User entity.
|
||||
func (u *User) QueryMentionedNotes() *NoteQuery {
|
||||
return NewUserClient(u.config).QueryMentionedNotes(u)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this User.
|
||||
// Note that you need to call User.Unwrap() before calling this method if this User
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (u *User) Update() *UserUpdateOne {
|
||||
return NewUserClient(u.config).UpdateOne(u)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the User entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (u *User) Unwrap() *User {
|
||||
_tx, ok := u.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: User is not a transactional entity")
|
||||
}
|
||||
u.config.driver = _tx.drv
|
||||
return u
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (u *User) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("User(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", u.ID))
|
||||
builder.WriteString("isRemote=")
|
||||
builder.WriteString(fmt.Sprintf("%v", u.IsRemote))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uri=")
|
||||
builder.WriteString(u.URI)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("extensions=")
|
||||
builder.WriteString(fmt.Sprintf("%v", u.Extensions))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(u.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(u.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("username=")
|
||||
builder.WriteString(u.Username)
|
||||
builder.WriteString(", ")
|
||||
if v := u.PasswordHash; v != nil {
|
||||
builder.WriteString("passwordHash=")
|
||||
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := u.DisplayName; v != nil {
|
||||
builder.WriteString("displayName=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := u.Biography; v != nil {
|
||||
builder.WriteString("biography=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("publicKey=")
|
||||
builder.WriteString(fmt.Sprintf("%v", u.PublicKey))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("privateKey=")
|
||||
builder.WriteString(fmt.Sprintf("%v", u.PrivateKey))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("indexable=")
|
||||
builder.WriteString(fmt.Sprintf("%v", u.Indexable))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("privacyLevel=")
|
||||
builder.WriteString(fmt.Sprintf("%v", u.PrivacyLevel))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("fields=")
|
||||
builder.WriteString(fmt.Sprintf("%v", u.Fields))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("inbox=")
|
||||
builder.WriteString(u.Inbox)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("featured=")
|
||||
builder.WriteString(u.Featured)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("followers=")
|
||||
builder.WriteString(u.Followers)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("following=")
|
||||
builder.WriteString(u.Following)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("outbox=")
|
||||
builder.WriteString(u.Outbox)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Users is a parsable slice of User.
|
||||
type Users []*User
|
||||
354
ent/user/user.go
Normal file
354
ent/user/user.go
Normal file
|
|
@ -0,0 +1,354 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the user type in the database.
|
||||
Label = "user"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldIsRemote holds the string denoting the isremote field in the database.
|
||||
FieldIsRemote = "is_remote"
|
||||
// FieldURI holds the string denoting the uri field in the database.
|
||||
FieldURI = "uri"
|
||||
// FieldExtensions holds the string denoting the extensions field in the database.
|
||||
FieldExtensions = "extensions"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldUsername holds the string denoting the username field in the database.
|
||||
FieldUsername = "username"
|
||||
// FieldPasswordHash holds the string denoting the passwordhash field in the database.
|
||||
FieldPasswordHash = "password_hash"
|
||||
// FieldDisplayName holds the string denoting the displayname field in the database.
|
||||
FieldDisplayName = "display_name"
|
||||
// FieldBiography holds the string denoting the biography field in the database.
|
||||
FieldBiography = "biography"
|
||||
// FieldPublicKey holds the string denoting the publickey field in the database.
|
||||
FieldPublicKey = "public_key"
|
||||
// FieldPrivateKey holds the string denoting the privatekey field in the database.
|
||||
FieldPrivateKey = "private_key"
|
||||
// FieldIndexable holds the string denoting the indexable field in the database.
|
||||
FieldIndexable = "indexable"
|
||||
// FieldPrivacyLevel holds the string denoting the privacylevel field in the database.
|
||||
FieldPrivacyLevel = "privacy_level"
|
||||
// FieldFields holds the string denoting the fields field in the database.
|
||||
FieldFields = "fields"
|
||||
// FieldInbox holds the string denoting the inbox field in the database.
|
||||
FieldInbox = "inbox"
|
||||
// FieldFeatured holds the string denoting the featured field in the database.
|
||||
FieldFeatured = "featured"
|
||||
// FieldFollowers holds the string denoting the followers field in the database.
|
||||
FieldFollowers = "followers"
|
||||
// FieldFollowing holds the string denoting the following field in the database.
|
||||
FieldFollowing = "following"
|
||||
// FieldOutbox holds the string denoting the outbox field in the database.
|
||||
FieldOutbox = "outbox"
|
||||
// EdgeAvatarImage holds the string denoting the avatarimage edge name in mutations.
|
||||
EdgeAvatarImage = "avatarImage"
|
||||
// EdgeHeaderImage holds the string denoting the headerimage edge name in mutations.
|
||||
EdgeHeaderImage = "headerImage"
|
||||
// EdgeAuthoredNotes holds the string denoting the authorednotes edge name in mutations.
|
||||
EdgeAuthoredNotes = "authoredNotes"
|
||||
// EdgeMentionedNotes holds the string denoting the mentionednotes edge name in mutations.
|
||||
EdgeMentionedNotes = "mentionedNotes"
|
||||
// Table holds the table name of the user in the database.
|
||||
Table = "users"
|
||||
// AvatarImageTable is the table that holds the avatarImage relation/edge.
|
||||
AvatarImageTable = "users"
|
||||
// AvatarImageInverseTable is the table name for the Image entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "image" package.
|
||||
AvatarImageInverseTable = "images"
|
||||
// AvatarImageColumn is the table column denoting the avatarImage relation/edge.
|
||||
AvatarImageColumn = "user_avatar_image"
|
||||
// HeaderImageTable is the table that holds the headerImage relation/edge.
|
||||
HeaderImageTable = "users"
|
||||
// HeaderImageInverseTable is the table name for the Image entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "image" package.
|
||||
HeaderImageInverseTable = "images"
|
||||
// HeaderImageColumn is the table column denoting the headerImage relation/edge.
|
||||
HeaderImageColumn = "user_header_image"
|
||||
// AuthoredNotesTable is the table that holds the authoredNotes relation/edge.
|
||||
AuthoredNotesTable = "notes"
|
||||
// AuthoredNotesInverseTable is the table name for the Note entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "note" package.
|
||||
AuthoredNotesInverseTable = "notes"
|
||||
// AuthoredNotesColumn is the table column denoting the authoredNotes relation/edge.
|
||||
AuthoredNotesColumn = "note_author"
|
||||
// MentionedNotesTable is the table that holds the mentionedNotes relation/edge. The primary key declared below.
|
||||
MentionedNotesTable = "note_mentions"
|
||||
// MentionedNotesInverseTable is the table name for the Note entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "note" package.
|
||||
MentionedNotesInverseTable = "notes"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for user fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldIsRemote,
|
||||
FieldURI,
|
||||
FieldExtensions,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldUsername,
|
||||
FieldPasswordHash,
|
||||
FieldDisplayName,
|
||||
FieldBiography,
|
||||
FieldPublicKey,
|
||||
FieldPrivateKey,
|
||||
FieldIndexable,
|
||||
FieldPrivacyLevel,
|
||||
FieldFields,
|
||||
FieldInbox,
|
||||
FieldFeatured,
|
||||
FieldFollowers,
|
||||
FieldFollowing,
|
||||
FieldOutbox,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "users"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"user_avatar_image",
|
||||
"user_header_image",
|
||||
}
|
||||
|
||||
var (
|
||||
// MentionedNotesPrimaryKey and MentionedNotesColumn2 are the table columns denoting the
|
||||
// primary key for the mentionedNotes relation (M2M).
|
||||
MentionedNotesPrimaryKey = []string{"note_id", "user_id"}
|
||||
)
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
URIValidator func(string) error
|
||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
||||
DefaultExtensions lysand.Extensions
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time
|
||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||
UpdateDefaultUpdatedAt func() time.Time
|
||||
// UsernameValidator is a validator for the "username" field. It is called by the builders before save.
|
||||
UsernameValidator func(string) error
|
||||
// DisplayNameValidator is a validator for the "displayName" field. It is called by the builders before save.
|
||||
DisplayNameValidator func(string) error
|
||||
// DefaultIndexable holds the default value on creation for the "indexable" field.
|
||||
DefaultIndexable bool
|
||||
// DefaultFields holds the default value on creation for the "fields" field.
|
||||
DefaultFields []lysand.Field
|
||||
// InboxValidator is a validator for the "inbox" field. It is called by the builders before save.
|
||||
InboxValidator func(string) error
|
||||
// FeaturedValidator is a validator for the "featured" field. It is called by the builders before save.
|
||||
FeaturedValidator func(string) error
|
||||
// FollowersValidator is a validator for the "followers" field. It is called by the builders before save.
|
||||
FollowersValidator func(string) error
|
||||
// FollowingValidator is a validator for the "following" field. It is called by the builders before save.
|
||||
FollowingValidator func(string) error
|
||||
// OutboxValidator is a validator for the "outbox" field. It is called by the builders before save.
|
||||
OutboxValidator func(string) error
|
||||
// DefaultID holds the default value on creation for the "id" field.
|
||||
DefaultID func() uuid.UUID
|
||||
)
|
||||
|
||||
// PrivacyLevel defines the type for the "privacyLevel" enum field.
|
||||
type PrivacyLevel string
|
||||
|
||||
// PrivacyLevelPublic is the default value of the PrivacyLevel enum.
|
||||
const DefaultPrivacyLevel = PrivacyLevelPublic
|
||||
|
||||
// PrivacyLevel values.
|
||||
const (
|
||||
PrivacyLevelPublic PrivacyLevel = "public"
|
||||
PrivacyLevelRestricted PrivacyLevel = "restricted"
|
||||
PrivacyLevelPrivate PrivacyLevel = "private"
|
||||
)
|
||||
|
||||
func (pl PrivacyLevel) String() string {
|
||||
return string(pl)
|
||||
}
|
||||
|
||||
// PrivacyLevelValidator is a validator for the "privacyLevel" field enum values. It is called by the builders before save.
|
||||
func PrivacyLevelValidator(pl PrivacyLevel) error {
|
||||
switch pl {
|
||||
case PrivacyLevelPublic, PrivacyLevelRestricted, PrivacyLevelPrivate:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("user: invalid enum value for privacyLevel field: %q", pl)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the User queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByIsRemote orders the results by the isRemote field.
|
||||
func ByIsRemote(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldIsRemote, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByURI orders the results by the uri field.
|
||||
func ByURI(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldURI, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUsername orders the results by the username field.
|
||||
func ByUsername(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUsername, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDisplayName orders the results by the displayName field.
|
||||
func ByDisplayName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDisplayName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByBiography orders the results by the biography field.
|
||||
func ByBiography(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldBiography, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByIndexable orders the results by the indexable field.
|
||||
func ByIndexable(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldIndexable, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByPrivacyLevel orders the results by the privacyLevel field.
|
||||
func ByPrivacyLevel(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldPrivacyLevel, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByInbox orders the results by the inbox field.
|
||||
func ByInbox(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldInbox, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByFeatured orders the results by the featured field.
|
||||
func ByFeatured(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldFeatured, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByFollowers orders the results by the followers field.
|
||||
func ByFollowers(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldFollowers, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByFollowing orders the results by the following field.
|
||||
func ByFollowing(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldFollowing, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByOutbox orders the results by the outbox field.
|
||||
func ByOutbox(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldOutbox, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAvatarImageField orders the results by avatarImage field.
|
||||
func ByAvatarImageField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newAvatarImageStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByHeaderImageField orders the results by headerImage field.
|
||||
func ByHeaderImageField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newHeaderImageStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByAuthoredNotesCount orders the results by authoredNotes count.
|
||||
func ByAuthoredNotesCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newAuthoredNotesStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByAuthoredNotes orders the results by authoredNotes terms.
|
||||
func ByAuthoredNotes(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newAuthoredNotesStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByMentionedNotesCount orders the results by mentionedNotes count.
|
||||
func ByMentionedNotesCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newMentionedNotesStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByMentionedNotes orders the results by mentionedNotes terms.
|
||||
func ByMentionedNotes(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newMentionedNotesStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newAvatarImageStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(AvatarImageInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, AvatarImageTable, AvatarImageColumn),
|
||||
)
|
||||
}
|
||||
func newHeaderImageStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(HeaderImageInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, HeaderImageTable, HeaderImageColumn),
|
||||
)
|
||||
}
|
||||
func newAuthoredNotesStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(AuthoredNotesInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, AuthoredNotesTable, AuthoredNotesColumn),
|
||||
)
|
||||
}
|
||||
func newMentionedNotesStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(MentionedNotesInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, MentionedNotesTable, MentionedNotesPrimaryKey...),
|
||||
)
|
||||
}
|
||||
1140
ent/user/where.go
Normal file
1140
ent/user/where.go
Normal file
File diff suppressed because it is too large
Load diff
1752
ent/user_create.go
Normal file
1752
ent/user_create.go
Normal file
File diff suppressed because it is too large
Load diff
88
ent/user_delete.go
Normal file
88
ent/user_delete.go
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
)
|
||||
|
||||
// UserDelete is the builder for deleting a User entity.
|
||||
type UserDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *UserMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserDelete builder.
|
||||
func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete {
|
||||
ud.mutation.Where(ps...)
|
||||
return ud
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (ud *UserDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ud *UserDelete) ExecX(ctx context.Context) int {
|
||||
n, err := ud.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID))
|
||||
if ps := ud.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, ud.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
ud.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// UserDeleteOne is the builder for deleting a single User entity.
|
||||
type UserDeleteOne struct {
|
||||
ud *UserDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserDelete builder.
|
||||
func (udo *UserDeleteOne) Where(ps ...predicate.User) *UserDeleteOne {
|
||||
udo.ud.mutation.Where(ps...)
|
||||
return udo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (udo *UserDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := udo.ud.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{user.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (udo *UserDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := udo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
868
ent/user_query.go
Normal file
868
ent/user_query.go
Normal file
|
|
@ -0,0 +1,868 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/image"
|
||||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
)
|
||||
|
||||
// UserQuery is the builder for querying User entities.
|
||||
type UserQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []user.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.User
|
||||
withAvatarImage *ImageQuery
|
||||
withHeaderImage *ImageQuery
|
||||
withAuthoredNotes *NoteQuery
|
||||
withMentionedNotes *NoteQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the UserQuery builder.
|
||||
func (uq *UserQuery) Where(ps ...predicate.User) *UserQuery {
|
||||
uq.predicates = append(uq.predicates, ps...)
|
||||
return uq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (uq *UserQuery) Limit(limit int) *UserQuery {
|
||||
uq.ctx.Limit = &limit
|
||||
return uq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (uq *UserQuery) Offset(offset int) *UserQuery {
|
||||
uq.ctx.Offset = &offset
|
||||
return uq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (uq *UserQuery) Unique(unique bool) *UserQuery {
|
||||
uq.ctx.Unique = &unique
|
||||
return uq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (uq *UserQuery) Order(o ...user.OrderOption) *UserQuery {
|
||||
uq.order = append(uq.order, o...)
|
||||
return uq
|
||||
}
|
||||
|
||||
// QueryAvatarImage chains the current query on the "avatarImage" edge.
|
||||
func (uq *UserQuery) QueryAvatarImage() *ImageQuery {
|
||||
query := (&ImageClient{config: uq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := uq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(image.Table, image.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, user.AvatarImageTable, user.AvatarImageColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryHeaderImage chains the current query on the "headerImage" edge.
|
||||
func (uq *UserQuery) QueryHeaderImage() *ImageQuery {
|
||||
query := (&ImageClient{config: uq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := uq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(image.Table, image.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, user.HeaderImageTable, user.HeaderImageColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryAuthoredNotes chains the current query on the "authoredNotes" edge.
|
||||
func (uq *UserQuery) QueryAuthoredNotes() *NoteQuery {
|
||||
query := (&NoteClient{config: uq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := uq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(note.Table, note.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, user.AuthoredNotesTable, user.AuthoredNotesColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryMentionedNotes chains the current query on the "mentionedNotes" edge.
|
||||
func (uq *UserQuery) QueryMentionedNotes() *NoteQuery {
|
||||
query := (&NoteClient{config: uq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := uq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(note.Table, note.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, user.MentionedNotesTable, user.MentionedNotesPrimaryKey...),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first User entity from the query.
|
||||
// Returns a *NotFoundError when no User was found.
|
||||
func (uq *UserQuery) First(ctx context.Context) (*User, error) {
|
||||
nodes, err := uq.Limit(1).All(setContextOp(ctx, uq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{user.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (uq *UserQuery) FirstX(ctx context.Context) *User {
|
||||
node, err := uq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first User ID from the query.
|
||||
// Returns a *NotFoundError when no User ID was found.
|
||||
func (uq *UserQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = uq.Limit(1).IDs(setContextOp(ctx, uq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{user.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (uq *UserQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := uq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single User entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one User entity is found.
|
||||
// Returns a *NotFoundError when no User entities are found.
|
||||
func (uq *UserQuery) Only(ctx context.Context) (*User, error) {
|
||||
nodes, err := uq.Limit(2).All(setContextOp(ctx, uq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{user.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{user.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (uq *UserQuery) OnlyX(ctx context.Context) *User {
|
||||
node, err := uq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only User ID in the query.
|
||||
// Returns a *NotSingularError when more than one User ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (uq *UserQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = &NotSingularError{user.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (uq *UserQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := uq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Users.
|
||||
func (uq *UserQuery) All(ctx context.Context) ([]*User, error) {
|
||||
ctx = setContextOp(ctx, uq.ctx, "All")
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*User, *UserQuery]()
|
||||
return withInterceptors[[]*User](ctx, uq, qr, uq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (uq *UserQuery) AllX(ctx context.Context) []*User {
|
||||
nodes, err := uq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of User IDs.
|
||||
func (uq *UserQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||
if uq.ctx.Unique == nil && uq.path != nil {
|
||||
uq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, uq.ctx, "IDs")
|
||||
if err = uq.Select(user.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (uq *UserQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||
ids, err := uq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (uq *UserQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, uq.ctx, "Count")
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, uq, querierCount[*UserQuery](), uq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (uq *UserQuery) CountX(ctx context.Context) int {
|
||||
count, err := uq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (uq *UserQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, uq.ctx, "Exist")
|
||||
switch _, err := uq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (uq *UserQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := uq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the UserQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (uq *UserQuery) Clone() *UserQuery {
|
||||
if uq == nil {
|
||||
return nil
|
||||
}
|
||||
return &UserQuery{
|
||||
config: uq.config,
|
||||
ctx: uq.ctx.Clone(),
|
||||
order: append([]user.OrderOption{}, uq.order...),
|
||||
inters: append([]Interceptor{}, uq.inters...),
|
||||
predicates: append([]predicate.User{}, uq.predicates...),
|
||||
withAvatarImage: uq.withAvatarImage.Clone(),
|
||||
withHeaderImage: uq.withHeaderImage.Clone(),
|
||||
withAuthoredNotes: uq.withAuthoredNotes.Clone(),
|
||||
withMentionedNotes: uq.withMentionedNotes.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: uq.sql.Clone(),
|
||||
path: uq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithAvatarImage tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "avatarImage" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (uq *UserQuery) WithAvatarImage(opts ...func(*ImageQuery)) *UserQuery {
|
||||
query := (&ImageClient{config: uq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
uq.withAvatarImage = query
|
||||
return uq
|
||||
}
|
||||
|
||||
// WithHeaderImage tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "headerImage" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (uq *UserQuery) WithHeaderImage(opts ...func(*ImageQuery)) *UserQuery {
|
||||
query := (&ImageClient{config: uq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
uq.withHeaderImage = query
|
||||
return uq
|
||||
}
|
||||
|
||||
// WithAuthoredNotes tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "authoredNotes" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (uq *UserQuery) WithAuthoredNotes(opts ...func(*NoteQuery)) *UserQuery {
|
||||
query := (&NoteClient{config: uq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
uq.withAuthoredNotes = query
|
||||
return uq
|
||||
}
|
||||
|
||||
// WithMentionedNotes tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "mentionedNotes" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (uq *UserQuery) WithMentionedNotes(opts ...func(*NoteQuery)) *UserQuery {
|
||||
query := (&NoteClient{config: uq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
uq.withMentionedNotes = query
|
||||
return uq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// IsRemote bool `json:"isRemote,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.User.Query().
|
||||
// GroupBy(user.FieldIsRemote).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||
uq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &UserGroupBy{build: uq}
|
||||
grbuild.flds = &uq.ctx.Fields
|
||||
grbuild.label = user.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// IsRemote bool `json:"isRemote,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.User.Query().
|
||||
// Select(user.FieldIsRemote).
|
||||
// Scan(ctx, &v)
|
||||
func (uq *UserQuery) Select(fields ...string) *UserSelect {
|
||||
uq.ctx.Fields = append(uq.ctx.Fields, fields...)
|
||||
sbuild := &UserSelect{UserQuery: uq}
|
||||
sbuild.label = user.Label
|
||||
sbuild.flds, sbuild.scan = &uq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a UserSelect configured with the given aggregations.
|
||||
func (uq *UserQuery) Aggregate(fns ...AggregateFunc) *UserSelect {
|
||||
return uq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (uq *UserQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range uq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, uq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range uq.ctx.Fields {
|
||||
if !user.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if uq.path != nil {
|
||||
prev, err := uq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
uq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, error) {
|
||||
var (
|
||||
nodes = []*User{}
|
||||
withFKs = uq.withFKs
|
||||
_spec = uq.querySpec()
|
||||
loadedTypes = [4]bool{
|
||||
uq.withAvatarImage != nil,
|
||||
uq.withHeaderImage != nil,
|
||||
uq.withAuthoredNotes != nil,
|
||||
uq.withMentionedNotes != nil,
|
||||
}
|
||||
)
|
||||
if uq.withAvatarImage != nil || uq.withHeaderImage != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, user.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*User).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &User{config: uq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, uq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := uq.withAvatarImage; query != nil {
|
||||
if err := uq.loadAvatarImage(ctx, query, nodes, nil,
|
||||
func(n *User, e *Image) { n.Edges.AvatarImage = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := uq.withHeaderImage; query != nil {
|
||||
if err := uq.loadHeaderImage(ctx, query, nodes, nil,
|
||||
func(n *User, e *Image) { n.Edges.HeaderImage = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := uq.withAuthoredNotes; query != nil {
|
||||
if err := uq.loadAuthoredNotes(ctx, query, nodes,
|
||||
func(n *User) { n.Edges.AuthoredNotes = []*Note{} },
|
||||
func(n *User, e *Note) { n.Edges.AuthoredNotes = append(n.Edges.AuthoredNotes, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := uq.withMentionedNotes; query != nil {
|
||||
if err := uq.loadMentionedNotes(ctx, query, nodes,
|
||||
func(n *User) { n.Edges.MentionedNotes = []*Note{} },
|
||||
func(n *User, e *Note) { n.Edges.MentionedNotes = append(n.Edges.MentionedNotes, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) loadAvatarImage(ctx context.Context, query *ImageQuery, nodes []*User, init func(*User), assign func(*User, *Image)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*User)
|
||||
for i := range nodes {
|
||||
if nodes[i].user_avatar_image == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].user_avatar_image
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(image.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_avatar_image" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (uq *UserQuery) loadHeaderImage(ctx context.Context, query *ImageQuery, nodes []*User, init func(*User), assign func(*User, *Image)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*User)
|
||||
for i := range nodes {
|
||||
if nodes[i].user_header_image == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].user_header_image
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(image.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_header_image" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (uq *UserQuery) loadAuthoredNotes(ctx context.Context, query *NoteQuery, nodes []*User, init func(*User), assign func(*User, *Note)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID]*User)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.Note(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(user.AuthoredNotesColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.note_author
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "note_author" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "note_author" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (uq *UserQuery) loadMentionedNotes(ctx context.Context, query *NoteQuery, nodes []*User, init func(*User), assign func(*User, *Note)) error {
|
||||
edgeIDs := make([]driver.Value, len(nodes))
|
||||
byID := make(map[uuid.UUID]*User)
|
||||
nids := make(map[uuid.UUID]map[*User]struct{})
|
||||
for i, node := range nodes {
|
||||
edgeIDs[i] = node.ID
|
||||
byID[node.ID] = node
|
||||
if init != nil {
|
||||
init(node)
|
||||
}
|
||||
}
|
||||
query.Where(func(s *sql.Selector) {
|
||||
joinT := sql.Table(user.MentionedNotesTable)
|
||||
s.Join(joinT).On(s.C(note.FieldID), joinT.C(user.MentionedNotesPrimaryKey[0]))
|
||||
s.Where(sql.InValues(joinT.C(user.MentionedNotesPrimaryKey[1]), edgeIDs...))
|
||||
columns := s.SelectedColumns()
|
||||
s.Select(joinT.C(user.MentionedNotesPrimaryKey[1]))
|
||||
s.AppendSelect(columns...)
|
||||
s.SetDistinct(false)
|
||||
})
|
||||
if err := query.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||
assign := spec.Assign
|
||||
values := spec.ScanValues
|
||||
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
values, err := values(columns[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append([]any{new(uuid.UUID)}, values...), nil
|
||||
}
|
||||
spec.Assign = func(columns []string, values []any) error {
|
||||
outValue := *values[0].(*uuid.UUID)
|
||||
inValue := *values[1].(*uuid.UUID)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*User]struct{}{byID[outValue]: {}}
|
||||
return assign(columns[1:], values[1:])
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
return nil
|
||||
}
|
||||
})
|
||||
})
|
||||
neighbors, err := withInterceptors[[]*Note](ctx, query, qr, query.inters)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected "mentionedNotes" node returned %v`, n.ID)
|
||||
}
|
||||
for kn := range nodes {
|
||||
assign(kn, n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := uq.querySpec()
|
||||
_spec.Node.Columns = uq.ctx.Fields
|
||||
if len(uq.ctx.Fields) > 0 {
|
||||
_spec.Unique = uq.ctx.Unique != nil && *uq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, uq.driver, _spec)
|
||||
}
|
||||
|
||||
func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID))
|
||||
_spec.From = uq.sql
|
||||
if unique := uq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if uq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := uq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != user.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := uq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := uq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := uq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := uq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(uq.driver.Dialect())
|
||||
t1 := builder.Table(user.Table)
|
||||
columns := uq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = user.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if uq.sql != nil {
|
||||
selector = uq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if uq.ctx.Unique != nil && *uq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range uq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range uq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := uq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := uq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// UserGroupBy is the group-by builder for User entities.
|
||||
type UserGroupBy struct {
|
||||
selector
|
||||
build *UserQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (ugb *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy {
|
||||
ugb.fns = append(ugb.fns, fns...)
|
||||
return ugb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ugb *UserGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ugb.build.ctx, "GroupBy")
|
||||
if err := ugb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*UserQuery, *UserGroupBy](ctx, ugb.build, ugb, ugb.build.inters, v)
|
||||
}
|
||||
|
||||
func (ugb *UserGroupBy) sqlScan(ctx context.Context, root *UserQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(ugb.fns))
|
||||
for _, fn := range ugb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*ugb.flds)+len(ugb.fns))
|
||||
for _, f := range *ugb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*ugb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ugb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// UserSelect is the builder for selecting fields of User entities.
|
||||
type UserSelect struct {
|
||||
*UserQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (us *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect {
|
||||
us.fns = append(us.fns, fns...)
|
||||
return us
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (us *UserSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, us.ctx, "Select")
|
||||
if err := us.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*UserQuery, *UserSelect](ctx, us.UserQuery, us, us.inters, v)
|
||||
}
|
||||
|
||||
func (us *UserSelect) sqlScan(ctx context.Context, root *UserQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(us.fns))
|
||||
for _, fn := range us.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*us.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := us.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
1456
ent/user_update.go
Normal file
1456
ent/user_update.go
Normal file
File diff suppressed because it is too large
Load diff
29
entsqlite.go
Normal file
29
entsqlite.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
"modernc.org/sqlite"
|
||||
)
|
||||
|
||||
type sqliteDriver struct {
|
||||
*sqlite.Driver
|
||||
}
|
||||
|
||||
func (d sqliteDriver) Open(name string) (driver.Conn, error) {
|
||||
log.Trace().Str("name", name).Msg("Opening SQLite connection")
|
||||
conn, err := d.Driver.Open(name)
|
||||
if err != nil {
|
||||
return conn, err
|
||||
}
|
||||
c := conn.(interface {
|
||||
Exec(stmt string, args []driver.Value) (driver.Result, error)
|
||||
})
|
||||
if _, err := c.Exec("PRAGMA foreign_keys = on;", nil); err != nil {
|
||||
conn.Close()
|
||||
return nil, errors.Wrap(err, "failed to enable enable foreign keys")
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
32
fiber_error_handler.go
Normal file
32
fiber_error_handler.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.devminer.xyz/devminer/unitel"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func fiberErrorHandler(c *fiber.Ctx, err error) error {
|
||||
var fiberErr *fiber.Error
|
||||
var apiErr *api_schema.APIError
|
||||
|
||||
if errors.As(err, &fiberErr) {
|
||||
apiErr = api_schema.NewAPIError(fiberErr.Code, fiberErr.Error())(nil)
|
||||
} else if errors.As(err, &apiErr) {
|
||||
log.Error().Err(apiErr).Msg("API error")
|
||||
} else {
|
||||
if hub := unitel.GetHubFromFiberContext(c); hub != nil {
|
||||
hub.CaptureException(err)
|
||||
}
|
||||
|
||||
log.Error().Err(err).Msg("Unhandled error")
|
||||
apiErr = api_schema.NewAPIError(fiber.StatusInternalServerError, "Internal Server Error")(nil)
|
||||
}
|
||||
|
||||
log.Error().Err(apiErr).Msg("Unhandled error")
|
||||
|
||||
return c.Status(apiErr.StatusCode).JSON(api_schema.NewFailedAPIResponse[any](apiErr))
|
||||
}
|
||||
91
go.mod
Normal file
91
go.mod
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
module github.com/lysand-org/versia-go
|
||||
|
||||
go 1.22.5
|
||||
|
||||
require (
|
||||
entgo.io/ent v0.13.1
|
||||
git.devminer.xyz/devminer/unitel v0.0.0-20240811005427-261161b9118d
|
||||
github.com/Masterminds/semver v1.5.0
|
||||
github.com/go-logr/logr v1.4.2
|
||||
github.com/go-logr/zerologr v1.2.3
|
||||
github.com/gofiber/fiber/v2 v2.52.5
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/jackc/pgx/v5 v5.6.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/rs/zerolog v1.33.0
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/ucarion/urlpath v0.0.0-20200424170820-7ccc79b76bbb
|
||||
github.com/valyala/fasthttp v1.55.0
|
||||
modernc.org/sqlite v1.31.1
|
||||
)
|
||||
|
||||
require (
|
||||
ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 // indirect
|
||||
github.com/agext/levenshtein v1.2.1 // indirect
|
||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/getsentry/sentry-go v0.28.1 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-openapi/inflect v0.19.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.22.0 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
github.com/klauspost/compress v1.17.9 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
||||
github.com/nats-io/nats.go v1.36.0 // indirect
|
||||
github.com/nats-io/nkeys v0.4.7 // indirect
|
||||
github.com/nats-io/nuid v1.0.1 // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/qustavo/sqlhooks/v2 v2.1.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
github.com/zclconf/go-cty v1.8.0 // indirect
|
||||
go.opentelemetry.io/otel v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/metric v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.28.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
|
||||
golang.org/x/crypto v0.26.0 // indirect
|
||||
golang.org/x/mod v0.19.0 // indirect
|
||||
golang.org/x/net v0.28.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.24.0 // indirect
|
||||
golang.org/x/text v0.17.0 // indirect
|
||||
golang.org/x/tools v0.23.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240808171019-573a1156607a // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240808171019-573a1156607a // indirect
|
||||
google.golang.org/grpc v1.65.0 // indirect
|
||||
google.golang.org/protobuf v1.34.2 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
|
||||
modernc.org/libc v1.55.3 // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
modernc.org/memory v1.8.0 // indirect
|
||||
modernc.org/strutil v1.2.0 // indirect
|
||||
modernc.org/token v1.1.0 // indirect
|
||||
)
|
||||
271
go.sum
Normal file
271
go.sum
Normal file
|
|
@ -0,0 +1,271 @@
|
|||
ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 h1:GwdJbXydHCYPedeeLt4x/lrlIISQ4JTH1mRWuE5ZZ14=
|
||||
ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43/go.mod h1:uj3pm+hUTVN/X5yfdBexHlZv+1Xu5u5ZbZx7+CDavNU=
|
||||
entgo.io/ent v0.13.1 h1:uD8QwN1h6SNphdCCzmkMN3feSUzNnVvV/WIkHKMbzOE=
|
||||
entgo.io/ent v0.13.1/go.mod h1:qCEmo+biw3ccBn9OyL4ZK5dfpwg++l1Gxwac5B1206A=
|
||||
git.devminer.xyz/devminer/unitel v0.0.0-20240731151502-6155fc58527e h1:D/evc8i/qVOI4aFB36zIksWjYto5ZJKhzdHP0FFQn8o=
|
||||
git.devminer.xyz/devminer/unitel v0.0.0-20240731151502-6155fc58527e/go.mod h1:+aDah0giu/eSjnr/pTNC+g6CTPyf4lttIIewNQ+1HaQ=
|
||||
git.devminer.xyz/devminer/unitel v0.0.0-20240731195827-7274c9b9631b h1:ky/+3Zyhpe7KOPuSKfmHcl7CWZUrEIxKPPKdmo1mjOY=
|
||||
git.devminer.xyz/devminer/unitel v0.0.0-20240731195827-7274c9b9631b/go.mod h1:+aDah0giu/eSjnr/pTNC+g6CTPyf4lttIIewNQ+1HaQ=
|
||||
git.devminer.xyz/devminer/unitel v0.0.0-20240810000007-3c254e87680c h1:iV8aKmhDzDEJMpCmidGfJ9v4++yDMAooGyMoCzJII8c=
|
||||
git.devminer.xyz/devminer/unitel v0.0.0-20240810000007-3c254e87680c/go.mod h1:+aDah0giu/eSjnr/pTNC+g6CTPyf4lttIIewNQ+1HaQ=
|
||||
git.devminer.xyz/devminer/unitel v0.0.0-20240811005427-261161b9118d h1:J+dcb2+nok6Ps10buowDOM6kA1/PUu0Mmcp5VMhTrho=
|
||||
git.devminer.xyz/devminer/unitel v0.0.0-20240811005427-261161b9118d/go.mod h1:+aDah0giu/eSjnr/pTNC+g6CTPyf4lttIIewNQ+1HaQ=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
|
||||
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
|
||||
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
|
||||
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
|
||||
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
|
||||
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
||||
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
|
||||
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/getsentry/sentry-go v0.28.1 h1:zzaSm/vHmGllRM6Tpx1492r0YDzauArdBfkJRtY6P5k=
|
||||
github.com/getsentry/sentry-go v0.28.1/go.mod h1:1fQZ+7l7eeJ3wYi82q5Hg8GqAPgefRq+FP/QhafYVgg=
|
||||
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
||||
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-logr/zerologr v1.2.3 h1:up5N9vcH9Xck3jJkXzgyOxozT14R47IyDODz8LM1KSs=
|
||||
github.com/go-logr/zerologr v1.2.3/go.mod h1:BxwGo7y5zgSHYR1BjbnHPyF/5ZjVKfKxAZANVu6E8Ho=
|
||||
github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4=
|
||||
github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao=
|
||||
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
|
||||
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
|
||||
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
|
||||
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd h1:gbpYu9NMq8jhDVbvlGkMFWCjLFlqqEZjEmObmhUy6Vo=
|
||||
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 h1:CWyXh/jylQWp2dtiV33mY4iSSp6yf4lmn+c7/tN+ObI=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0/go.mod h1:nCLIt0w3Ept2NwF8ThLmrppXsfT07oC8k0XNDxd8sVU=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc=
|
||||
github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
|
||||
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
|
||||
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
|
||||
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
|
||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
|
||||
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
|
||||
github.com/nats-io/nats.go v1.36.0 h1:suEUPuWzTSse/XhESwqLxXGuj8vGRuPRoG7MoRN/qyU=
|
||||
github.com/nats-io/nats.go v1.36.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
|
||||
github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
|
||||
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
|
||||
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
|
||||
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/qustavo/sqlhooks/v2 v2.1.0 h1:54yBemHnGHp/7xgT+pxwmIlMSDNYKx5JW5dfRAiCZi0=
|
||||
github.com/qustavo/sqlhooks/v2 v2.1.0/go.mod h1:aMREyKo7fOKTwiLuWPsaHRXEmtqG4yREztO0idF83AU=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
||||
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
||||
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/ucarion/urlpath v0.0.0-20200424170820-7ccc79b76bbb h1:Ywfo8sUltxogBpFuMOFRrrSifO788kAFxmvVw31PtQQ=
|
||||
github.com/ucarion/urlpath v0.0.0-20200424170820-7ccc79b76bbb/go.mod h1:ikPs9bRWicNw3S7XpJ8sK/smGwU9WcSVU3dy9qahYBM=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8=
|
||||
github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM=
|
||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
|
||||
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
|
||||
github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA=
|
||||
github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
|
||||
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
|
||||
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 h1:U2guen0GhqH8o/G2un8f/aG/y++OuW6MyCo6hT9prXk=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0/go.mod h1:yeGZANgEcpdx/WK0IvvRFC+2oLiMS2u4L/0Rj2M2Qr0=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 h1:R3X6ZXmNPRR8ul6i3WgFURCHzaXjHdm0karRG/+dj3s=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0/go.mod h1:QWFXnDavXWwMx2EEcZsf3yxgEKAqsxQ+Syjp+seyInw=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.28.0 h1:BJee2iLkfRfl9lc7aFmBwkWxY/RI1RDdXepSF6y8TPE=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.28.0/go.mod h1:DIzlHs3DRscCIBU3Y9YSzPfScwnYnzfnCd4g8zA7bZc=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0 h1:EVSnY9JbEEW92bEkIYOVMw4q1WJxIAGoFTrtYOzWuRQ=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0/go.mod h1:Ea1N1QQryNXpCD0I1fdLibBAIpQuBkznMmkdKrapk1Y=
|
||||
go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
|
||||
go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
|
||||
go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE=
|
||||
go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.28.0 h1:OkuaKgKrgAbYrrY0t92c+cC+2F6hsFNnCQArXCKlg08=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.28.0/go.mod h1:cWPjykihLAPvXKi4iZc1dpER3Jdq2Z0YLse3moQUCpg=
|
||||
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
|
||||
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
||||
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
||||
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
||||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
||||
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
|
||||
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
|
||||
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
||||
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
|
||||
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
|
||||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
|
||||
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
|
||||
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
|
||||
google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM=
|
||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf h1:GillM0Ef0pkZPIB+5iO6SDK+4T9pf6TpaYR6ICD5rVE=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf/go.mod h1:OFMYQFHJ4TM3JRlWDZhJbZfra2uqc3WLBZiaaqP4DtU=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240808171019-573a1156607a h1:KyUe15n7B1YCu+kMmPtlXxgkLQbp+Dw0tCRZf9Sd+CE=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240808171019-573a1156607a/go.mod h1:4+X6GvPs+25wZKbQq9qyAXrwIRExv7w0Ea6MgZLZiDM=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf h1:liao9UHurZLtiEwBgT9LMOnKYsHze6eA6w1KQCMVN2Q=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240808171019-573a1156607a h1:EKiZZXueP9/T68B8Nl0GAx9cjbQnCId0yP3qPMgaaHs=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240808171019-573a1156607a/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
|
||||
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
|
||||
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
|
||||
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
modernc.org/cc/v4 v4.21.4 h1:3Be/Rdo1fpr8GrQ7IVw9OHtplU4gWbb+wNgeoBMmGLQ=
|
||||
modernc.org/cc/v4 v4.21.4/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ=
|
||||
modernc.org/ccgo/v4 v4.19.2 h1:lwQZgvboKD0jBwdaeVCTouxhxAyN6iawF3STraAal8Y=
|
||||
modernc.org/ccgo/v4 v4.19.2/go.mod h1:ysS3mxiMV38XGRTTcgo0DQTeTmAO4oCmJl1nX9VFI3s=
|
||||
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
|
||||
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
|
||||
modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw=
|
||||
modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
|
||||
modernc.org/libc v1.55.3 h1:AzcW1mhlPNrRtjS5sS+eW2ISCgSOLLNyFzRh/V3Qj/U=
|
||||
modernc.org/libc v1.55.3/go.mod h1:qFXepLhz+JjFThQ4kzwzOjA/y/artDeg+pcYnY+Q83w=
|
||||
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
|
||||
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
|
||||
modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E=
|
||||
modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU=
|
||||
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
|
||||
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
||||
modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc=
|
||||
modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss=
|
||||
modernc.org/sqlite v1.31.1 h1:XVU0VyzxrYHlBhIs1DiEgSl0ZtdnPtbLVy8hSkzxGrs=
|
||||
modernc.org/sqlite v1.31.1/go.mod h1:UqoylwmTb9F+IqXERT8bW9zzOWN8qwAIcLdzeBZs4hA=
|
||||
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
|
||||
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
86
internal/api_schema/api.go
Normal file
86
internal/api_schema/api.go
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
package api_schema
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type APIError struct {
|
||||
StatusCode int `json:"status_code"`
|
||||
Description string `json:"description"`
|
||||
Metadata map[string]any `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
func (e APIError) Error() string {
|
||||
if e.Metadata == nil || len(e.Metadata) == 0 {
|
||||
return fmt.Sprintf("APIError: %d - %s", e.StatusCode, e.Description)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("APIError: %d - %s, %s", e.StatusCode, e.Description, stringifyErrorMetadata(e.Metadata))
|
||||
}
|
||||
|
||||
func stringifyErrorMetadata(m map[string]any) string {
|
||||
sb := strings.Builder{}
|
||||
for key, value := range m {
|
||||
sb.WriteString(fmt.Sprintf("%s=%v, ", key, value))
|
||||
}
|
||||
return strings.TrimSuffix(sb.String(), ", ")
|
||||
}
|
||||
|
||||
func (e APIError) Equals(other any) bool {
|
||||
var err *APIError
|
||||
|
||||
switch raw := other.(type) {
|
||||
case *APIError:
|
||||
err = raw
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
return e.StatusCode == err.StatusCode && e.Description == err.Description
|
||||
}
|
||||
|
||||
func (e APIError) URLEncode() (string, error) {
|
||||
v := url.Values{}
|
||||
v.Set("status_code", fmt.Sprintf("%d", e.StatusCode))
|
||||
v.Set("description", e.Description)
|
||||
|
||||
if e.Metadata != nil {
|
||||
b, err := json.Marshal(e.Metadata)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
v.Set("metadata", string(b))
|
||||
}
|
||||
|
||||
// Fix up spaces because Golang's net/url.URL encodes " " as "+" instead of "%20"
|
||||
// https://github.com/golang/go/issues/13982
|
||||
return strings.ReplaceAll(v.Encode(), "+", "%20"), nil
|
||||
}
|
||||
|
||||
func NewAPIError(code int, description string) func(metadata map[string]any) *APIError {
|
||||
return func(metadata map[string]any) *APIError {
|
||||
return &APIError{StatusCode: code, Description: description, Metadata: metadata}
|
||||
}
|
||||
}
|
||||
|
||||
type APIResponse[T any] struct {
|
||||
Ok bool `json:"ok"`
|
||||
Data *T `json:"data"`
|
||||
Error *APIError `json:"error"`
|
||||
}
|
||||
|
||||
func NewFailedAPIResponse[T any](err error) APIResponse[T] {
|
||||
var e *APIError
|
||||
|
||||
if errors.As(err, &e) {
|
||||
} else {
|
||||
e = NewAPIError(500, err.Error())(nil)
|
||||
}
|
||||
|
||||
return APIResponse[T]{Ok: false, Error: e}
|
||||
}
|
||||
15
internal/api_schema/errors.go
Normal file
15
internal/api_schema/errors.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package api_schema
|
||||
|
||||
var (
|
||||
ErrBadRequest = NewAPIError(400, "Bad request")
|
||||
ErrInvalidRequestBody = NewAPIError(400, "Invalid request body")
|
||||
ErrUnauthorized = NewAPIError(401, "Unauthorized")
|
||||
ErrForbidden = NewAPIError(403, "Forbidden")
|
||||
ErrNotFound = NewAPIError(404, "Not found")
|
||||
ErrConflict = NewAPIError(409, "Conflict")
|
||||
ErrUsernameTaken = NewAPIError(409, "Username is taken")
|
||||
ErrRateLimitExceeded = NewAPIError(429, "Rate limit exceeded")
|
||||
|
||||
ErrInternalServerError = NewAPIError(500, "Internal server error")
|
||||
ErrNotImplemented = NewAPIError(501, "Not implemented")
|
||||
)
|
||||
18
internal/api_schema/notes.go
Normal file
18
internal/api_schema/notes.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package api_schema
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
type Note struct {
|
||||
ID uuid.UUID `json:"id,string"`
|
||||
}
|
||||
|
||||
type FetchNoteResponse = APIResponse[Note]
|
||||
|
||||
type CreateNoteRequest struct {
|
||||
Content string `json:"content" validate:"required,min=1,max=1024"`
|
||||
Visibility lysand.PublicationVisibility `json:"visibility" validate:"required,oneof=public private direct"`
|
||||
Mentions []lysand.URL `json:"mentions"`
|
||||
}
|
||||
17
internal/api_schema/users.go
Normal file
17
internal/api_schema/users.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package api_schema
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID uuid.UUID `json:"id,string"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type FetchUserResponse = APIResponse[User]
|
||||
|
||||
type CreateUserRequest struct {
|
||||
Username string `json:"username" validate:"required,username_regex,min=3,max=32"`
|
||||
Password string `json:"password" validate:"required,min=8,max=256"`
|
||||
}
|
||||
85
internal/database/transaction.go
Normal file
85
internal/database/transaction.go
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"git.devminer.xyz/devminer/unitel"
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
)
|
||||
|
||||
func BeginTx(ctx context.Context, db *ent.Client, telemetry *unitel.Telemetry) (*Tx, error) {
|
||||
span := telemetry.StartSpan(ctx, "db.sql.transaction", "BeginTx")
|
||||
ctx = span.Context()
|
||||
|
||||
tx, err := db.Tx(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newTx(tx, ctx, span), nil
|
||||
}
|
||||
|
||||
type TxAction uint8
|
||||
|
||||
const (
|
||||
TxActionRollback TxAction = iota
|
||||
TxActionCommit
|
||||
)
|
||||
|
||||
type Tx struct {
|
||||
*ent.Tx
|
||||
ctx context.Context
|
||||
span *unitel.Span
|
||||
|
||||
m sync.Mutex
|
||||
action TxAction
|
||||
|
||||
finishOnce func() error
|
||||
}
|
||||
|
||||
func newTx(tx *ent.Tx, ctx context.Context, span *unitel.Span) *Tx {
|
||||
t := &Tx{
|
||||
Tx: tx,
|
||||
ctx: ctx,
|
||||
span: span,
|
||||
}
|
||||
|
||||
t.finishOnce = sync.OnceValue(t.finish)
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *Tx) MarkForCommit() {
|
||||
t.m.Lock()
|
||||
defer t.m.Unlock()
|
||||
|
||||
t.action = TxActionCommit
|
||||
}
|
||||
|
||||
func (t *Tx) finish() error {
|
||||
t.m.Lock()
|
||||
defer t.m.Unlock()
|
||||
defer t.span.End()
|
||||
|
||||
var err error
|
||||
switch t.action {
|
||||
case TxActionCommit:
|
||||
err = t.Tx.Commit()
|
||||
case TxActionRollback:
|
||||
err = t.Tx.Rollback()
|
||||
}
|
||||
if err != nil {
|
||||
t.span.CaptureError(err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *Tx) Context() context.Context {
|
||||
return t.ctx
|
||||
}
|
||||
|
||||
func (t *Tx) Finish() error {
|
||||
return t.finishOnce()
|
||||
}
|
||||
76
internal/entity/follow.go
Normal file
76
internal/entity/follow.go
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
package entity
|
||||
|
||||
import (
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
type Follow struct {
|
||||
*ent.Follow
|
||||
|
||||
URI *lysand.URL
|
||||
FollowerURI *lysand.URL
|
||||
FolloweeURI *lysand.URL
|
||||
}
|
||||
|
||||
func NewFollow(dbFollow *ent.Follow) (*Follow, error) {
|
||||
f := &Follow{Follow: dbFollow}
|
||||
|
||||
var err error
|
||||
|
||||
f.URI, err = lysand.ParseURL(dbFollow.URI)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f.FollowerURI, err = lysand.ParseURL(dbFollow.Edges.Follower.URI)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f.FolloweeURI, err = lysand.ParseURL(dbFollow.Edges.Followee.URI)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func (f Follow) ToLysand() *lysand.Follow {
|
||||
return &lysand.Follow{
|
||||
Entity: lysand.Entity{
|
||||
ID: f.ID,
|
||||
URI: f.URI,
|
||||
CreatedAt: lysand.TimeFromStd(f.CreatedAt),
|
||||
Extensions: f.Extensions,
|
||||
},
|
||||
Author: f.FollowerURI,
|
||||
Followee: f.FolloweeURI,
|
||||
}
|
||||
}
|
||||
|
||||
func (f Follow) ToLysandAccept() *lysand.FollowAccept {
|
||||
return &lysand.FollowAccept{
|
||||
Entity: lysand.Entity{
|
||||
ID: f.ID,
|
||||
URI: f.URI,
|
||||
CreatedAt: lysand.TimeFromStd(f.CreatedAt),
|
||||
Extensions: f.Extensions,
|
||||
},
|
||||
Author: f.FolloweeURI,
|
||||
Follower: f.FollowerURI,
|
||||
}
|
||||
}
|
||||
|
||||
func (f Follow) ToLysandReject() *lysand.FollowReject {
|
||||
return &lysand.FollowReject{
|
||||
Entity: lysand.Entity{
|
||||
ID: f.ID,
|
||||
URI: f.URI,
|
||||
CreatedAt: lysand.TimeFromStd(f.CreatedAt),
|
||||
Extensions: f.Extensions,
|
||||
},
|
||||
Author: f.FolloweeURI,
|
||||
Follower: f.FollowerURI,
|
||||
}
|
||||
}
|
||||
70
internal/entity/note.go
Normal file
70
internal/entity/note.go
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
package entity
|
||||
|
||||
import (
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
type Note struct {
|
||||
*ent.Note
|
||||
URI *lysand.URL
|
||||
Content lysand.TextContentTypeMap
|
||||
Author *User
|
||||
Mentions []User
|
||||
MentionURIs []lysand.URL
|
||||
}
|
||||
|
||||
func NewNote(dbNote *ent.Note) (*Note, error) {
|
||||
n := &Note{
|
||||
Note: dbNote,
|
||||
Content: lysand.TextContentTypeMap{
|
||||
"text/plain": lysand.TextContent{Content: dbNote.Content},
|
||||
},
|
||||
Mentions: make([]User, 0, len(dbNote.Edges.Mentions)),
|
||||
MentionURIs: make([]lysand.URL, 0, len(dbNote.Edges.Mentions)),
|
||||
}
|
||||
|
||||
var err error
|
||||
if n.URI, err = lysand.ParseURL(dbNote.URI); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if n.Author, err = NewUser(dbNote.Edges.Author); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, m := range dbNote.Edges.Mentions {
|
||||
u, err := NewUser(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
n.Mentions = append(n.Mentions, *u)
|
||||
n.MentionURIs = append(n.MentionURIs, *u.URI)
|
||||
}
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (n Note) ToLysand() lysand.Note {
|
||||
return lysand.Note{
|
||||
Entity: lysand.Entity{
|
||||
ID: n.ID,
|
||||
URI: n.URI,
|
||||
CreatedAt: lysand.TimeFromStd(n.CreatedAt),
|
||||
Extensions: n.Extensions,
|
||||
},
|
||||
Author: n.Author.URI,
|
||||
Content: n.Content,
|
||||
Category: nil,
|
||||
Device: nil,
|
||||
Previews: nil,
|
||||
Group: nil,
|
||||
Attachments: nil,
|
||||
RepliesTo: nil,
|
||||
Quoting: nil,
|
||||
Mentions: n.MentionURIs,
|
||||
Subject: n.Subject,
|
||||
IsSensitive: &n.IsSensitive,
|
||||
Visibility: lysand.PublicationVisibility(n.Visibility),
|
||||
}
|
||||
}
|
||||
139
internal/entity/user.go
Normal file
139
internal/entity/user.go
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
package entity
|
||||
|
||||
import (
|
||||
"github.com/lysand-org/versia-go/internal/helpers"
|
||||
"net/url"
|
||||
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
"github.com/lysand-org/versia-go/internal/utils"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
*ent.User
|
||||
|
||||
URI *lysand.URL
|
||||
Inbox *lysand.URL
|
||||
Outbox *lysand.URL
|
||||
Featured *lysand.URL
|
||||
Followers *lysand.URL
|
||||
Following *lysand.URL
|
||||
|
||||
DisplayName string
|
||||
LysandAvatar lysand.ImageContentTypeMap
|
||||
LysandBiography lysand.TextContentTypeMap
|
||||
Signer lysand.Signer
|
||||
}
|
||||
|
||||
func NewUser(dbUser *ent.User) (*User, error) {
|
||||
u := &User{User: dbUser}
|
||||
|
||||
u.DisplayName = u.Username
|
||||
if dbUser.DisplayName != nil {
|
||||
u.DisplayName = *dbUser.DisplayName
|
||||
}
|
||||
|
||||
var err error
|
||||
if u.URI, err = lysand.ParseURL(dbUser.URI); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.Inbox, err = lysand.ParseURL(dbUser.Inbox); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.Outbox, err = lysand.ParseURL(dbUser.Outbox); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.Featured, err = lysand.ParseURL(dbUser.Featured); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.Followers, err = lysand.ParseURL(dbUser.Followers); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.Following, err = lysand.ParseURL(dbUser.Following); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
u.LysandAvatar = lysandAvatar(dbUser)
|
||||
u.LysandBiography = lysandBiography(dbUser)
|
||||
u.Signer = lysand.Signer{
|
||||
PrivateKey: dbUser.PrivateKey,
|
||||
UserURL: u.URI.ToStd(),
|
||||
}
|
||||
|
||||
return u, nil
|
||||
}
|
||||
|
||||
func (u User) ToLysand() *lysand.User {
|
||||
return &lysand.User{
|
||||
Entity: lysand.Entity{
|
||||
ID: u.ID,
|
||||
URI: u.URI,
|
||||
CreatedAt: lysand.TimeFromStd(u.CreatedAt),
|
||||
Extensions: u.Extensions,
|
||||
},
|
||||
DisplayName: helpers.StringPtr(u.DisplayName),
|
||||
Username: u.Username,
|
||||
Avatar: u.LysandAvatar,
|
||||
Header: imageMap(u.Edges.HeaderImage),
|
||||
Indexable: u.Indexable,
|
||||
PublicKey: lysand.PublicKey{
|
||||
Actor: utils.UserAPIURL(u.ID),
|
||||
PublicKey: lysand.SPKIPublicKey(u.PublicKey),
|
||||
},
|
||||
Bio: u.LysandBiography,
|
||||
Fields: u.Fields,
|
||||
|
||||
Inbox: u.Inbox,
|
||||
Outbox: u.Outbox,
|
||||
Featured: u.Featured,
|
||||
Followers: u.Followers,
|
||||
Following: u.Following,
|
||||
|
||||
// TODO: Remove these, they got deprecated and moved into an extension
|
||||
Likes: utils.UserLikesAPIURL(u.ID),
|
||||
Dislikes: utils.UserDislikesAPIURL(u.ID),
|
||||
}
|
||||
}
|
||||
|
||||
func lysandAvatar(u *ent.User) lysand.ImageContentTypeMap {
|
||||
if avatar := imageMap(u.Edges.AvatarImage); avatar != nil {
|
||||
return avatar
|
||||
}
|
||||
|
||||
return lysand.ImageContentTypeMap{
|
||||
"image/svg+xml": lysand.ImageContent{
|
||||
Content: utils.DefaultAvatarURL(u.ID),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func lysandBiography(u *ent.User) lysand.TextContentTypeMap {
|
||||
if u.Biography == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: Render HTML
|
||||
|
||||
return lysand.TextContentTypeMap{
|
||||
"text/html": lysand.TextContent{
|
||||
Content: *u.Biography,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func imageMap(i *ent.Image) lysand.ImageContentTypeMap {
|
||||
if i == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
u, err := url.Parse(i.URL)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return lysand.ImageContentTypeMap{
|
||||
i.MimeType: {
|
||||
Content: (*lysand.URL)(u),
|
||||
},
|
||||
}
|
||||
}
|
||||
33
internal/handlers/follow_handler/handler.go
Normal file
33
internal/handlers/follow_handler/handler.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package follow_handler
|
||||
|
||||
import (
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/lysand-org/versia-go/config"
|
||||
"github.com/lysand-org/versia-go/internal/service"
|
||||
"github.com/lysand-org/versia-go/pkg/webfinger"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
followService service.FollowService
|
||||
federationService service.FederationService
|
||||
|
||||
hostMeta webfinger.HostMeta
|
||||
|
||||
log logr.Logger
|
||||
}
|
||||
|
||||
func New(followService service.FollowService, federationService service.FederationService, log logr.Logger) *Handler {
|
||||
return &Handler{
|
||||
followService: followService,
|
||||
federationService: federationService,
|
||||
|
||||
hostMeta: webfinger.NewHostMeta(config.C.PublicAddress),
|
||||
|
||||
log: log.WithName("users"),
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Handler) Register(r fiber.Router) {
|
||||
r.Get("/api/follows/:id", i.GetLysandFollow)
|
||||
}
|
||||
28
internal/handlers/follow_handler/lysand_follow_get.go
Normal file
28
internal/handlers/follow_handler/lysand_follow_get.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package follow_handler
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
)
|
||||
|
||||
func (i *Handler) GetLysandFollow(c *fiber.Ctx) error {
|
||||
parsedRequestedFollowID, err := uuid.Parse(c.Params("id"))
|
||||
if err != nil {
|
||||
return api_schema.ErrBadRequest(map[string]any{"reason": "Invalid follow ID"})
|
||||
}
|
||||
|
||||
f, err := i.followService.GetFollow(c.UserContext(), parsedRequestedFollowID)
|
||||
if err != nil {
|
||||
i.log.Error(err, "Failed to query follow", "id", parsedRequestedFollowID)
|
||||
|
||||
return api_schema.ErrInternalServerError(map[string]any{"reason": "Failed to query follow"})
|
||||
}
|
||||
if f == nil {
|
||||
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
|
||||
"error": "Follow not found",
|
||||
})
|
||||
}
|
||||
|
||||
return c.JSON(f.ToLysand())
|
||||
}
|
||||
28
internal/handlers/meta_handler/handler.go
Normal file
28
internal/handlers/meta_handler/handler.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package meta_handler
|
||||
|
||||
import (
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/lysand-org/versia-go/config"
|
||||
"github.com/lysand-org/versia-go/pkg/webfinger"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
hostMeta webfinger.HostMeta
|
||||
|
||||
log logr.Logger
|
||||
}
|
||||
|
||||
func New(log logr.Logger) *Handler {
|
||||
return &Handler{
|
||||
hostMeta: webfinger.NewHostMeta(config.C.PublicAddress),
|
||||
|
||||
log: log.WithName("users"),
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Handler) Register(r fiber.Router) {
|
||||
r.Get("/.well-known/lysand", i.GetLysandServerMetadata)
|
||||
r.Get("/.well-known/host-meta", i.GetHostMeta)
|
||||
r.Get("/.well-known/host-meta.json", i.GetHostMetaJSON)
|
||||
}
|
||||
28
internal/handlers/meta_handler/lysand_server_metadata_get.go
Normal file
28
internal/handlers/meta_handler/lysand_server_metadata_get.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package meta_handler
|
||||
|
||||
import (
|
||||
"github.com/Masterminds/semver"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/lysand-org/versia-go/config"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
func (i *Handler) GetLysandServerMetadata(c *fiber.Ctx) error {
|
||||
return c.JSON(lysand.ServerMetadata{
|
||||
// TODO: Get version from build linker flags
|
||||
Version: semver.MustParse("0.0.0-dev"),
|
||||
|
||||
Name: config.C.InstanceName,
|
||||
Description: config.C.InstanceDescription,
|
||||
Website: lysand.URLFromStd(config.C.PublicAddress),
|
||||
|
||||
// TODO: Get more info
|
||||
Moderators: nil,
|
||||
Admins: nil,
|
||||
Logo: nil,
|
||||
Banner: nil,
|
||||
|
||||
SupportedExtensions: []string{},
|
||||
Extensions: map[string]any{},
|
||||
})
|
||||
}
|
||||
23
internal/handlers/meta_handler/wellknown_host_meta.go
Normal file
23
internal/handlers/meta_handler/wellknown_host_meta.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package meta_handler
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func (i *Handler) GetHostMeta(c *fiber.Ctx) error {
|
||||
if c.Accepts(fiber.MIMEApplicationJSON) != "" {
|
||||
return i.GetHostMetaJSON(c)
|
||||
}
|
||||
|
||||
if c.Accepts(fiber.MIMEApplicationXML) != "" {
|
||||
c.Set(fiber.HeaderContentType, fiber.MIMEApplicationXMLCharsetUTF8)
|
||||
return c.Send(i.hostMeta.XML)
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusNotAcceptable).SendString("Not Acceptable")
|
||||
}
|
||||
|
||||
func (i *Handler) GetHostMetaJSON(c *fiber.Ctx) error {
|
||||
c.Set(fiber.HeaderContentType, fiber.MIMEApplicationJSONCharsetUTF8)
|
||||
return c.Send(i.hostMeta.JSON)
|
||||
}
|
||||
32
internal/handlers/note_handler/app_note_create.go
Normal file
32
internal/handlers/note_handler/app_note_create.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package note_handler
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
)
|
||||
|
||||
func (i *Handler) CreateNote(c *fiber.Ctx) error {
|
||||
req := api_schema.CreateNoteRequest{}
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"error": "invalid request",
|
||||
})
|
||||
}
|
||||
if err := i.bodyValidator.Validate(req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n, err := i.noteService.CreateNote(c.UserContext(), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n == nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": "failed to create note",
|
||||
})
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusCreated).JSON(api_schema.Note{
|
||||
ID: n.ID,
|
||||
})
|
||||
}
|
||||
28
internal/handlers/note_handler/app_note_get.go
Normal file
28
internal/handlers/note_handler/app_note_get.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package note_handler
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
)
|
||||
|
||||
func (i *Handler) GetNote(c *fiber.Ctx) error {
|
||||
parsedRequestedNoteID, err := uuid.Parse(c.Params("id"))
|
||||
if err != nil {
|
||||
return api_schema.ErrBadRequest(map[string]any{
|
||||
"reason": "Invalid note ID",
|
||||
})
|
||||
}
|
||||
|
||||
u, err := i.noteService.GetNote(c.UserContext(), parsedRequestedNoteID)
|
||||
if err != nil {
|
||||
i.log.Error(err, "Failed to query note", "id", parsedRequestedNoteID)
|
||||
|
||||
return api_schema.ErrInternalServerError(map[string]any{"reason": "Failed to query note"})
|
||||
}
|
||||
if u == nil {
|
||||
return api_schema.ErrNotFound(nil)
|
||||
}
|
||||
|
||||
return c.JSON(u.ToLysand())
|
||||
}
|
||||
35
internal/handlers/note_handler/handler.go
Normal file
35
internal/handlers/note_handler/handler.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package note_handler
|
||||
|
||||
import (
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/lysand-org/versia-go/config"
|
||||
"github.com/lysand-org/versia-go/internal/service"
|
||||
"github.com/lysand-org/versia-go/internal/validators"
|
||||
"github.com/lysand-org/versia-go/pkg/webfinger"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
noteService service.NoteService
|
||||
bodyValidator validators.BodyValidator
|
||||
|
||||
hostMeta webfinger.HostMeta
|
||||
|
||||
log logr.Logger
|
||||
}
|
||||
|
||||
func New(noteService service.NoteService, bodyValidator validators.BodyValidator, log logr.Logger) *Handler {
|
||||
return &Handler{
|
||||
noteService: noteService,
|
||||
bodyValidator: bodyValidator,
|
||||
|
||||
hostMeta: webfinger.NewHostMeta(config.C.PublicAddress),
|
||||
|
||||
log: log.WithName("users"),
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Handler) Register(r fiber.Router) {
|
||||
r.Get("/api/app/notes/:id", i.GetNote)
|
||||
r.Post("/api/app/notes/", i.CreateNote)
|
||||
}
|
||||
35
internal/handlers/user_handler/app_user_create.go
Normal file
35
internal/handlers/user_handler/app_user_create.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package user_handler
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
)
|
||||
|
||||
func (i *Handler) CreateUser(c *fiber.Ctx) error {
|
||||
var req api_schema.CreateUserRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return api_schema.ErrInvalidRequestBody(nil)
|
||||
}
|
||||
|
||||
if err := i.bodyValidator.Validate(req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
u, err := i.userService.NewUser(c.UserContext(), req.Username, req.Password)
|
||||
if err != nil {
|
||||
// TODO: Wrap this in a custom error
|
||||
if ent.IsConstraintError(err) {
|
||||
return api_schema.ErrUsernameTaken(nil)
|
||||
}
|
||||
|
||||
i.log.Error(err, "Failed to create user", "username", req.Username)
|
||||
|
||||
return api_schema.ErrInternalServerError(nil)
|
||||
}
|
||||
|
||||
return c.JSON(api_schema.User{
|
||||
ID: u.ID,
|
||||
Username: u.Username,
|
||||
})
|
||||
}
|
||||
31
internal/handlers/user_handler/app_user_get.go
Normal file
31
internal/handlers/user_handler/app_user_get.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package user_handler
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
)
|
||||
|
||||
func (i *Handler) GetUser(c *fiber.Ctx) error {
|
||||
parsedRequestedUserID, err := uuid.Parse(c.Params("id"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"error": "Invalid user ID",
|
||||
})
|
||||
}
|
||||
|
||||
u, err := i.userService.GetUserByID(c.UserContext(), parsedRequestedUserID)
|
||||
if err != nil {
|
||||
i.log.Error(err, "Failed to query user", "id", parsedRequestedUserID)
|
||||
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": "Failed to query user",
|
||||
})
|
||||
|
||||
}
|
||||
if u == nil {
|
||||
return api_schema.ErrNotFound(map[string]any{"id": parsedRequestedUserID})
|
||||
}
|
||||
|
||||
return c.JSON(u)
|
||||
}
|
||||
46
internal/handlers/user_handler/handler.go
Normal file
46
internal/handlers/user_handler/handler.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package user_handler
|
||||
|
||||
import (
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/lysand-org/versia-go/internal/service"
|
||||
"github.com/lysand-org/versia-go/internal/validators"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
userService service.UserService
|
||||
federationService service.FederationService
|
||||
inboxService service.InboxService
|
||||
|
||||
bodyValidator validators.BodyValidator
|
||||
requestValidator validators.RequestValidator
|
||||
|
||||
log logr.Logger
|
||||
}
|
||||
|
||||
func New(userService service.UserService, federationService service.FederationService, inboxService service.InboxService, bodyValidator validators.BodyValidator, requestValidator validators.RequestValidator, log logr.Logger) *Handler {
|
||||
return &Handler{
|
||||
userService: userService,
|
||||
federationService: federationService,
|
||||
inboxService: inboxService,
|
||||
|
||||
bodyValidator: bodyValidator,
|
||||
requestValidator: requestValidator,
|
||||
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Handler) Register(r fiber.Router) {
|
||||
// TODO: Handle this differently
|
||||
// There might be other routes that might want to also add their stuff to the robots.txt
|
||||
r.Get("/robots.txt", i.RobotsTXT)
|
||||
|
||||
r.Get("/.well-known/webfinger", i.Webfinger)
|
||||
|
||||
r.Get("/api/app/users/:id", i.GetUser)
|
||||
r.Post("/api/app/users/", i.CreateUser)
|
||||
|
||||
r.Get("/api/users/:id", i.GetLysandUser)
|
||||
r.Post("/api/users/:id/inbox", i.LysandInbox)
|
||||
}
|
||||
57
internal/handlers/user_handler/lysand_inbox.go
Normal file
57
internal/handlers/user_handler/lysand_inbox.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package user_handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/lysand-org/versia-go/internal/validators/val_impls"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
func (i *Handler) LysandInbox(c *fiber.Ctx) error {
|
||||
if err := i.requestValidator.ValidateFiberCtx(c.UserContext(), c); err != nil {
|
||||
if errors.Is(err, val_impls.ErrInvalidSignature) {
|
||||
i.log.Error(err, "Invalid signature")
|
||||
return c.SendStatus(fiber.StatusUnauthorized)
|
||||
}
|
||||
|
||||
i.log.Error(err, "Failed to validate signature")
|
||||
return err
|
||||
}
|
||||
|
||||
var raw json.RawMessage
|
||||
if err := json.Unmarshal(c.Body(), &raw); err != nil {
|
||||
i.log.Error(err, "Failed to unmarshal inbox object")
|
||||
return api_schema.ErrBadRequest(nil)
|
||||
}
|
||||
|
||||
obj, err := lysand.ParseInboxObject(raw)
|
||||
if err != nil {
|
||||
i.log.Error(err, "Failed to parse inbox object")
|
||||
|
||||
if errors.Is(err, lysand.ErrUnknownType{}) {
|
||||
return api_schema.ErrNotFound(map[string]any{
|
||||
"error": fmt.Sprintf("Unknown object type: %s", err.(lysand.ErrUnknownType).Type),
|
||||
})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
userId, err := uuid.Parse(c.Params("id"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"error": "Invalid user ID",
|
||||
})
|
||||
}
|
||||
|
||||
if err := i.inboxService.Handle(c.UserContext(), obj, userId); err != nil {
|
||||
i.log.Error(err, "Failed to handle inbox", "user", userId)
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
31
internal/handlers/user_handler/lysand_user_get.go
Normal file
31
internal/handlers/user_handler/lysand_user_get.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package user_handler
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
)
|
||||
|
||||
func (i *Handler) GetLysandUser(c *fiber.Ctx) error {
|
||||
parsedRequestedUserID, err := uuid.Parse(c.Params("id"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"error": "Invalid user ID",
|
||||
})
|
||||
}
|
||||
|
||||
u, err := i.userService.GetUserByID(c.UserContext(), parsedRequestedUserID)
|
||||
if err != nil {
|
||||
i.log.Error(err, "Failed to query user", "id", parsedRequestedUserID)
|
||||
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": "Failed to query user",
|
||||
"id": parsedRequestedUserID,
|
||||
})
|
||||
}
|
||||
if u == nil {
|
||||
return api_schema.ErrNotFound(map[string]any{"id": parsedRequestedUserID})
|
||||
}
|
||||
|
||||
return c.JSON(u.ToLysand())
|
||||
}
|
||||
9
internal/handlers/user_handler/robots_txt.go
Normal file
9
internal/handlers/user_handler/robots_txt.go
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
package user_handler
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func (i *Handler) RobotsTXT(c *fiber.Ctx) error {
|
||||
return c.SendString("")
|
||||
}
|
||||
32
internal/handlers/user_handler/wellknown_webfinger.go
Normal file
32
internal/handlers/user_handler/wellknown_webfinger.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package user_handler
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/lysand-org/versia-go/config"
|
||||
"github.com/lysand-org/versia-go/internal/helpers"
|
||||
"github.com/lysand-org/versia-go/pkg/webfinger"
|
||||
)
|
||||
|
||||
func (i *Handler) Webfinger(c *fiber.Ctx) error {
|
||||
userID, err := webfinger.ParseResource(c.Query("resource"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(webfinger.Response{
|
||||
Error: helpers.StringPtr(err.Error()),
|
||||
})
|
||||
}
|
||||
|
||||
if userID.Domain != config.C.PublicAddress.Host {
|
||||
return c.Status(fiber.StatusNotFound).JSON(webfinger.Response{
|
||||
Error: helpers.StringPtr("The requested user is a remote user"),
|
||||
})
|
||||
}
|
||||
|
||||
wf, err := i.userService.GetWebfingerForUser(c.UserContext(), userID.ID)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(webfinger.Response{
|
||||
Error: helpers.StringPtr("Failed to query user"),
|
||||
})
|
||||
}
|
||||
|
||||
return c.JSON(wf.WebFingerResource())
|
||||
}
|
||||
22
internal/helpers/crypto.go
Normal file
22
internal/helpers/crypto.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"time"
|
||||
)
|
||||
|
||||
func HashSHA256(data []byte) []byte {
|
||||
h := sha256.New()
|
||||
|
||||
h.Write(data)
|
||||
|
||||
return h.Sum(nil)
|
||||
}
|
||||
|
||||
func ISO8601(t time.Time) string {
|
||||
return t.Format("2006-01-02T15:04:05Z")
|
||||
}
|
||||
|
||||
func ParseISO8601(s string) (time.Time, error) {
|
||||
return time.Parse("2006-01-02T15:04:05Z", s)
|
||||
}
|
||||
5
internal/helpers/ptr.go
Normal file
5
internal/helpers/ptr.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package helpers
|
||||
|
||||
func StringPtr(s string) *string {
|
||||
return &s
|
||||
}
|
||||
171
internal/repository/repo_impls/follow_repository_impl.go
Normal file
171
internal/repository/repo_impls/follow_repository_impl.go
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
package repo_impls
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/lysand-org/versia-go/internal/repository"
|
||||
|
||||
"git.devminer.xyz/devminer/unitel"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
"github.com/lysand-org/versia-go/ent/follow"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/internal/entity"
|
||||
"github.com/lysand-org/versia-go/internal/utils"
|
||||
)
|
||||
|
||||
var ErrFollowAlreadyExists = errors.New("follow already exists")
|
||||
|
||||
var _ repository.FollowRepository = (*FollowRepositoryImpl)(nil)
|
||||
|
||||
type FollowRepositoryImpl struct {
|
||||
db *ent.Client
|
||||
log logr.Logger
|
||||
telemetry *unitel.Telemetry
|
||||
}
|
||||
|
||||
func NewFollowRepositoryImpl(db *ent.Client, log logr.Logger, telemetry *unitel.Telemetry) repository.FollowRepository {
|
||||
return &FollowRepositoryImpl{
|
||||
db: db,
|
||||
log: log,
|
||||
telemetry: telemetry,
|
||||
}
|
||||
}
|
||||
|
||||
func (i FollowRepositoryImpl) GetByID(ctx context.Context, id uuid.UUID) (*entity.Follow, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repository/repo_impls.FollowRepositoryImpl.GetByID").
|
||||
AddAttribute("followID", id)
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
||||
f, err := i.db.Follow.Query().
|
||||
Where(follow.ID(id)).
|
||||
WithFollowee().
|
||||
WithFollower().
|
||||
Only(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.AddAttribute("follower", f.Edges.Follower.URI).
|
||||
AddAttribute("followee", f.Edges.Followee.URI).
|
||||
AddAttribute("followURI", f.URI)
|
||||
|
||||
return entity.NewFollow(f)
|
||||
}
|
||||
|
||||
func (i FollowRepositoryImpl) Follow(ctx context.Context, follower, followee *entity.User) (*entity.Follow, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repository/repo_impls.FollowRepositoryImpl.Follow").
|
||||
AddAttribute("follower", follower.URI).
|
||||
AddAttribute("followee", followee.URI)
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
||||
fid := uuid.New()
|
||||
|
||||
fid, err := i.db.Follow.Create().
|
||||
SetID(fid).
|
||||
SetIsRemote(false).
|
||||
SetURI(utils.UserAPIURL(fid).String()).
|
||||
SetStatus(follow.StatusPending).
|
||||
SetFollower(follower.User).
|
||||
SetFollowee(followee.User).
|
||||
OnConflictColumns(follow.FollowerColumn, follow.FolloweeColumn).
|
||||
UpdateStatus().
|
||||
ID(ctx)
|
||||
if err != nil {
|
||||
if !ent.IsConstraintError(err) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, ErrFollowAlreadyExists
|
||||
}
|
||||
|
||||
s.AddAttribute("followID", fid)
|
||||
|
||||
f, err := i.db.Follow.Query().
|
||||
Where(follow.ID(fid)).
|
||||
WithFollowee().
|
||||
WithFollower().
|
||||
Only(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.AddAttribute("followURI", f.URI)
|
||||
|
||||
return entity.NewFollow(f)
|
||||
}
|
||||
|
||||
func (i FollowRepositoryImpl) Unfollow(ctx context.Context, follower, followee *entity.User) error {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repository/repo_impls.FollowRepositoryImpl.Unfollow").
|
||||
AddAttribute("follower", follower.URI).
|
||||
AddAttribute("followee", followee.URI)
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
||||
n, err := i.db.Follow.Delete().
|
||||
Where(matchFollowUsers(follower, followee)).
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
s.CaptureError(err)
|
||||
} else {
|
||||
s.AddAttribute("deleted", n).
|
||||
CaptureMessage(fmt.Sprintf("Deleted %d follow(s)", n))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i FollowRepositoryImpl) AcceptFollow(ctx context.Context, follower, followee *entity.User) error {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repository/repo_impls.FollowRepositoryImpl.AcceptFollow").
|
||||
AddAttribute("follower", follower.URI).
|
||||
AddAttribute("followee", followee.URI)
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
||||
n, err := i.db.Follow.Update().
|
||||
Where(matchFollowUsers(follower, followee), follow.StatusEQ(follow.StatusPending)).
|
||||
SetStatus(follow.StatusAccepted).
|
||||
Save(ctx)
|
||||
if err != nil {
|
||||
s.CaptureError(err)
|
||||
} else {
|
||||
s.CaptureMessage(fmt.Sprintf("Accepted %d follow(s)", n))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (i FollowRepositoryImpl) RejectFollow(ctx context.Context, follower, followee *entity.User) error {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repository/repo_impls.FollowRepositoryImpl.RejectFollow").
|
||||
AddAttribute("follower", follower.URI).
|
||||
AddAttribute("followee", followee.URI)
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
||||
n, err := i.db.Follow.Delete().
|
||||
Where(follow.And(matchFollowUsers(follower, followee), follow.StatusEQ(follow.StatusPending))).
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
s.CaptureError(err)
|
||||
} else {
|
||||
s.CaptureMessage(fmt.Sprintf("Deleted %d follow(s)", n))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func matchFollowUsers(follower, followee *entity.User) predicate.Follow {
|
||||
return follow.And(
|
||||
follow.HasFollowerWith(
|
||||
user.ID(follower.ID), user.ID(followee.ID),
|
||||
),
|
||||
follow.HasFolloweeWith(
|
||||
user.ID(follower.ID), user.ID(followee.ID),
|
||||
),
|
||||
)
|
||||
}
|
||||
90
internal/repository/repo_impls/manager.go
Normal file
90
internal/repository/repo_impls/manager.go
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
package repo_impls
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/lysand-org/versia-go/internal/repository"
|
||||
|
||||
"git.devminer.xyz/devminer/unitel"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
"github.com/lysand-org/versia-go/internal/database"
|
||||
)
|
||||
|
||||
type Factory[T any] func(db *ent.Client, log logr.Logger, telemetry *unitel.Telemetry) T
|
||||
|
||||
var _ repository.Manager = (*ManagerImpl)(nil)
|
||||
|
||||
type ManagerImpl struct {
|
||||
users repository.UserRepository
|
||||
notes repository.NoteRepository
|
||||
follows repository.FollowRepository
|
||||
|
||||
uRFactory Factory[repository.UserRepository]
|
||||
nRFactory Factory[repository.NoteRepository]
|
||||
fRFactory Factory[repository.FollowRepository]
|
||||
|
||||
db *ent.Client
|
||||
log logr.Logger
|
||||
telemetry *unitel.Telemetry
|
||||
}
|
||||
|
||||
func NewManagerImpl(db *ent.Client, telemetry *unitel.Telemetry, log logr.Logger, userRepositoryFunc Factory[repository.UserRepository], noteRepositoryFunc Factory[repository.NoteRepository], followRepositoryFunc Factory[repository.FollowRepository]) *ManagerImpl {
|
||||
userRepository := userRepositoryFunc(db, log.WithName("users"), telemetry)
|
||||
noteRepository := noteRepositoryFunc(db, log.WithName("notes"), telemetry)
|
||||
followRepository := followRepositoryFunc(db, log.WithName("follows"), telemetry)
|
||||
|
||||
return &ManagerImpl{
|
||||
users: userRepository,
|
||||
notes: noteRepository,
|
||||
follows: followRepository,
|
||||
|
||||
uRFactory: userRepositoryFunc,
|
||||
nRFactory: noteRepositoryFunc,
|
||||
fRFactory: followRepositoryFunc,
|
||||
|
||||
db: db,
|
||||
log: log,
|
||||
telemetry: telemetry,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *ManagerImpl) withDB(db *ent.Client) *ManagerImpl {
|
||||
return NewManagerImpl(db, i.telemetry, i.log, i.uRFactory, i.nRFactory, i.fRFactory)
|
||||
}
|
||||
|
||||
func (i *ManagerImpl) Atomic(ctx context.Context, fn func(ctx context.Context, tx repository.Manager) error) error {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repository/repo_impls.ManagerImpl.Atomic")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
||||
tx, err := database.BeginTx(ctx, i.db, i.telemetry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func(tx *database.Tx) {
|
||||
err := tx.Finish()
|
||||
if err != nil {
|
||||
i.log.Error(err, "Failed to finish transaction")
|
||||
}
|
||||
}(tx)
|
||||
|
||||
if err := fn(ctx, i.withDB(tx.Client())); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tx.MarkForCommit()
|
||||
|
||||
return tx.Finish()
|
||||
}
|
||||
|
||||
func (i *ManagerImpl) Users() repository.UserRepository {
|
||||
return i.users
|
||||
}
|
||||
|
||||
func (i *ManagerImpl) Notes() repository.NoteRepository {
|
||||
return i.notes
|
||||
}
|
||||
|
||||
func (i *ManagerImpl) Follows() repository.FollowRepository {
|
||||
return i.follows
|
||||
}
|
||||
117
internal/repository/repo_impls/note_repository_impl.go
Normal file
117
internal/repository/repo_impls/note_repository_impl.go
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
package repo_impls
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/lysand-org/versia-go/internal/repository"
|
||||
|
||||
"git.devminer.xyz/devminer/unitel"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/internal/entity"
|
||||
"github.com/lysand-org/versia-go/internal/utils"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
var _ repository.NoteRepository = (*NoteRepositoryImpl)(nil)
|
||||
|
||||
type NoteRepositoryImpl struct {
|
||||
db *ent.Client
|
||||
log logr.Logger
|
||||
telemetry *unitel.Telemetry
|
||||
}
|
||||
|
||||
func NewNoteRepositoryImpl(db *ent.Client, log logr.Logger, telemetry *unitel.Telemetry) repository.NoteRepository {
|
||||
return &NoteRepositoryImpl{
|
||||
db: db,
|
||||
log: log,
|
||||
telemetry: telemetry,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *NoteRepositoryImpl) NewNote(ctx context.Context, author *entity.User, content string, mentions []*entity.User) (*entity.Note, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repository/repo_impls.NoteRepositoryImpl.NewNote")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
||||
nid := uuid.New()
|
||||
|
||||
n, err := i.db.Note.Create().
|
||||
SetID(nid).
|
||||
SetIsRemote(false).
|
||||
SetURI(utils.NoteAPIURL(nid).String()).
|
||||
SetAuthor(author.User).
|
||||
SetContent(content).
|
||||
AddMentions(utils.MapSlice(mentions, func(m *entity.User) *ent.User { return m.User })...).
|
||||
Save(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
n, err = i.db.Note.Query().
|
||||
Where(note.ID(nid)).
|
||||
WithAuthor().
|
||||
WithMentions().
|
||||
Only(ctx)
|
||||
if err != nil {
|
||||
i.log.Error(err, "Failed to query author", "id", nid)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return entity.NewNote(n)
|
||||
}
|
||||
|
||||
func (i *NoteRepositoryImpl) ImportLysandNote(ctx context.Context, lNote *lysand.Note) (*entity.Note, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repository/repo_impls.NoteRepositoryImpl.ImportLysandNote")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
||||
id, err := i.db.Note.Create().
|
||||
SetID(uuid.New()).
|
||||
SetIsRemote(true).
|
||||
SetURI(lNote.URI.String()).
|
||||
OnConflict().
|
||||
UpdateNewValues().
|
||||
ID(ctx)
|
||||
if err != nil {
|
||||
i.log.Error(err, "Failed to import note into database", "uri", lNote.URI)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
n, err := i.db.Note.Get(ctx, id)
|
||||
if err != nil {
|
||||
i.log.Error(err, "Failed to get imported note", "id", id, "uri", lNote.URI)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
i.log.V(2).Info("Imported note into database", "id", id, "uri", lNote.URI)
|
||||
|
||||
return entity.NewNote(n)
|
||||
}
|
||||
|
||||
func (i *NoteRepositoryImpl) GetByID(ctx context.Context, id uuid.UUID) (*entity.Note, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repository/repo_impls.NoteRepositoryImpl.LookupByIDOrUsername")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
||||
n, err := i.db.Note.Query().
|
||||
Where(note.ID(id)).
|
||||
WithAuthor().
|
||||
WithMentions().
|
||||
Only(ctx)
|
||||
if err != nil {
|
||||
if !ent.IsNotFound(err) {
|
||||
i.log.Error(err, "Failed to query user", "id", id)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
i.log.V(2).Info("User not found in DB", "id", id)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
i.log.V(2).Info("User found in DB", "id", id)
|
||||
|
||||
return entity.NewNote(n)
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue